我的表單從隨機工作線程上的另一個對象接收異步回調。我一直在使用代理將數據傳遞給主線程(可用於更新屏幕控件),如下所示。性能是可怕的 - 一旦我達到每秒500次更新,程序完全鎖定。我的GUI處理本身不是問題,因爲我可以在窗體中模擬這種級別的更新並且沒有問題。我應該使用更有效的機制將數據從線程切換到線程嗎?Windows窗體線程和事件 - 切換事件的最有效方式?
delegate void DStatus(MyStatus obj);
DStatus _status; // set to MainThreadOnStatus during construction
// this function only called on form's owner thread
void MainThreadOnStatus(MyStatus obj)
{
// screen updates here as needed
}
// this function called by arbitrary worker threads in external facility
void OnStatus(MyStatus obj)
{
this.BeginInvoke(_status, obj);
}
MarshalByRefObject對單個appdomain中的線程邊界有影響嗎?我認爲它只適用於你有多個應用程序域。 – Eric 2008-09-24 23:15:10