按下按钮后调用以下函数。
Task.Factory.StartNew(() =>
{
Parallel.For(0, cyclesCount, i => DoWork(i));
if (OnJobCompleted != null)
OnJobCompleted(this, EventArgs.Empty);
});
代码中还有
void ladder_OnJobCompleted(object sender, EventArgs args)
{
txbDebug.Text = "completed";
}
我知道
txbDebug.Text = "completed";
必须被调用,因为我在不同的线程上引发事件。但我不知道如何调用它。此事件位于 wpf 窗体中。
最佳答案
使用Dispatcher
txbDebug.Dispatcher.Invoke(new Action(() =>
{
txbDebug.Text = "completed";
}));
关于c# - 在 Parallel.For 完成作业后引发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7378381/