这是否比设置后台工作线程效率低?因为它运作良好,看起来更清洁。在循环中,我调用BeginInvoke 3x - 向主窗口datagrid添加行,并更新进度条和消息。这种线程在WPF/C#中效率低吗?
public MyConstructor()
{
InitializeComponent();
ThreadStart start = delegate()
{
for (...)
{
...
MyWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new Action(delegate()
{
// Do something on the MyWindow thread.
}
));
...
}
// Intensive loop now done and we close this processing window.
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new Action(delegate()
{
this.Close();
}
));
}; // ThreadStart
new Thread(start).Start();
}
+1,'BackgroundWorker'提供了一个有用和清晰的多线程功能,我看不到任何理由避免使用它 – Damascus 2011-04-06 09:09:40