Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys. i want to continuously send an At command request to some specified phone number which my datareader retreived from the Database, and keep executing using a thread until the last record in the datareader is reached. but i know really know how to pass the parameter withing the thread. here is the code i have presently.
lease guys i need any help from any one is welcome.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System.Net;
using System.Web.Services;
using System.Web.Security;
using System.Configuration;
using System.Threading;
using System.Data;
using System.Data.SqlClient;

public partial class VehicleEnforaGPSSchedule : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public void Application_Init(Object sender, EventArgs e)
    {
        Threading();
    }

    public string GetConnectionString()
    {
        return ConfigurationManager.ConnectionStrings["EnforaTrackerConnectionString"].ConnectionString;
    }

    protected void Threading()
    {
         using(SqlConnection connection = new SqlConnection(GetConnectionString()))
        {
            string command = "SELECT [VehiclePhoneNumber] FROM [tbl_Vehicle_Data]";
            SqlCommand cmd = new SqlCommand(command, connection);
            cmd.CommandType = System.Data.CommandType.Text;
            SqlDataReader reader;
            try
            {
                connection.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    if (reader.HasRows)
                    {
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            GistMeGps g = new GistMeGps();
                            Thread thread = new Thread(new ThreadStart(g.RequestGPSCoordinate(i.ToString())));
                            thread.Start(i.ToString());
                            return;
                        }
                    }
                }
            }
            catch (SqlException sqlex)
            {
                lblError.Text = sqlex.ToString();
            }
        }

    }
}

public class GistMeGps
{
    public void RequestGPSCoordinate(string phoneNo)
    {
        UriBuilder urlBuilder = new UriBuilder();
        urlBuilder.Host = "192.168.1.125";
        urlBuilder.Port = 8800;

        string PhoneNumber = phoneNo;
        string message = ">RSP=T;ID=011252000596969;AT$GPSRD=10<";

        urlBuilder.Query = string.Format("PhoneNumber=%2B" + PhoneNumber + "&Text=" + message);

        HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri(urlBuilder.ToString(), false));
        HttpWebResponse httpResponse = (HttpWebResponse)(httpReq.GetResponse());
    }
}
Posted
Updated 27-Sep-11 22:15pm
v3

1 solution

Take the Return statement out of your for loop - that might improve things a little...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900