c#如何多线程处理for循环
1个回答
展开全部
1.可以用多线程做
private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(LoadForm));
t.Start();
}
private void LoadForm()
{
for (int i = 0; i < 9; i++)
{
Thread.Sleep(1000);
this.Invoke(new MyDelegate(SetRich), i.ToString());
}
}
delegate void MyDelegate(string str);//定义委托
private void SetRich(string str)//委托
{
textBox1.Text = str;
}
2.还可以用timer控件
private void Form1_Load(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(LoadForm));
t.Start();
}
private void LoadForm()
{
for (int i = 0; i < 9; i++)
{
Thread.Sleep(1000);
this.Invoke(new MyDelegate(SetRich), i.ToString());
}
}
delegate void MyDelegate(string str);//定义委托
private void SetRich(string str)//委托
{
textBox1.Text = str;
}
2.还可以用timer控件
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询