每次用户提交后,都会启动一个线程,(会很多人提交),每一秒执行一次任务。直到任务执行完成。退出循环。。但是我不确定当前的这个线程是否终止了。或者有什么办法手动终止呢?
protected void Button1_Click(object sender, EventArgs e)
{
doService ds = new doService(this.TextBox1.Text,"2","3");
Thread ts = new Thread(new ThreadStart(ds.SentMsg));
ts.Start();
}
public class doService
{
public string IbcID { get; set; }
public string TimeSpan { get; set; }
public string OrderID { get; set; }
public doService(string ibcid, string timespan, string orderid)
{
IbcID = ibcid;
TimeSpan = timespan;
OrderID = orderid;
}
public void SentMsg()
{
bool loop = true;
int i = 0;
while (loop)
{
i++;
string ok = IbcID + "_" + TimeSpan + "_" + OrderID;
System.IO.File.WriteAllText("d:\\" + IbcID + "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt", ok);
if (i == 10) { loop = false; }
Thread.Sleep(2000);
}
}
}