這是否比設置後臺工作線程效率低?因爲它運作良好,看起來更清潔。在循環中,我調用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