您的位置:首页 > 其它

多线程和委托简单例子

2011-08-12 10:33 260 查看
private void btnRun_Click(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(heating));
th.IsBackground = true;
th.Start();

}
int templeture;
delegate void DisplayHandler(string tempStr);

protected void heating()
{

for (int i = 0; i < 100; i++)
{
templeture = i;
string tp = i.ToString();
//this.Invoke(new DisplayHandler(Displaytemp));//这里是不带参数
this.BeginInvoke(new DisplayHandler(Displaytemp), tp);//带参数据
Thread.Sleep(1000);

}
}
protected void Displaytemp(string tempStr)
{

this.label1.Text = tempStr;// templeture.ToString();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: