【发布时间】:2012-10-25 05:36:19
【问题描述】:
以下代码使 UI 线程挂起。
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(Func);
t.Start();
}
private void Func()
{
this.Invoke((Action)(() =>
{
while (true);
}));
}
我希望在不同的工作线程中调用 Func(),而不会在每次单击按钮时冻结任何 UI 线程。
最好的解决方法是什么?
【问题讨论】:
-
为什么你把
while (true);放在Invoke方法中,你没有任何代码改变UI,它会阻塞UI线程, -
我想在循环中添加一些代码更改 UI。我只是在循环中省略了这些代码以使其看起来简单。谢谢。
标签: c# multithreading invoke