直接这样写
var task1 = Task.Factory.StartNew(() => DoSomeWork(message1, message2));
如果是winform,你在另外一个线程不能直接访问窗体控件,可以用
private void button1_Click(object sender, EventArgs e)
{
Task t1 = Task.Factory.StartNew(() => k1());
Task t2 = Task.Factory.StartNew(() => k2());
}
void k1()
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(100);
this.Invoke(new Action(
() => { this.label1.Text = i.ToString(); }));
}
}
void k2()
{
for (int i = 0; i < 100; i++)
{
Thread.Sleep(100);
this.Invoke(new Action(
() => { this.label2.Text = i.ToString(); }));
}
}