[英]C# Threading error + Backgroundworker component
我收到錯誤消息,當我嘗試通過調度程序更新UI元素時,對象引用未設置為對象實例。
示例代碼是->
backgroundworker.DoWork += >
{
// do some work here.
// close the progressbar over here
_progressBar.Dispatcher.Invoke(DispatcherPriority.Normal,
new Action( _progressBar.Close);
}
我收到未在_progressBar.Dispatcher.Invoke語句中設置的錯誤對象引用,並且我的應用程序完全掛起。
您確定_progressBar
的值不為null嗎? 也許在另一個時間點它為null
。
我將添加以下行進行檢查:
new Action(() => {
if (_progressBar == null){
if (Debugger.IsAttached){
Debugger.Break();
} else {
Debug.Fail("_progressbar is null!");
}
} else {
_progressBar.Close();
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.