帮助参数化线程 [英] Help with parametrize threading
本文介绍了帮助参数化线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好.我想连续向某个指定的电话号码发送At命令请求,该电话号码是我的数据读取器从数据库检索到的,并继续使用线程执行直到到达数据读取器中的最后一条记录.但我真的知道如何随线程传递参数.这是我目前拥有的代码.
租赁人员,欢迎任何需要我帮助的人.
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.
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());
}
}
推荐答案
GPSRD = 10<"; urlBuilder.Query = 字符串 .Format(" +电话号码+ & Text =" +消息); HttpWebRequest httpReq =(HttpWebRequest)WebRequest.Create(新 Uri(urlBuilder.ToString(), false )) ; HttpWebResponse httpResponse =(HttpWebResponse)(httpReq.GetResponse()); } }
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()); } }
将Return语句从您的for
循环中删除-可能会有所改善...
Take the Return statement out of your for
loop - that might improve things a little...
这篇关于帮助参数化线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文