- [C#] BackgroundWorker 範例1
- [C#] BackgroundWorker 範例2
- [C#] BackgroundWorker 範例3
- [C#] BackgroundWorker 範例4
- [C#] BackgroundWorker - Exception
Property
Method
Event
官方文件說明
You must be careful not to manipulate any user-interface objects in your DoWork event handler. Instead, communicate to the user interface through the ProgressChanged and RunWorkerCompleted events.DoWork 為非同步作業,ProgressChanged 和 RunWorkerCompleted 仍然是在 main thread 內進行作業
Property 和 Method 對應表
當 Property = true 時,才可以使用 Method
DoWorkEventArgs
參數傳遞表
Exception Handle
DoWork 內發生 Exception,必須在 RunWorkerCompleted Event 內透過 RunWorkerCompletedEventArgs.Error 來處理
官方文件說明
If the operation raises an exception that your code does not handle, the BackgroundWorker catches the exception and passes it into the RunWorkerCompleted event handler, where it is exposed as the Error property of System.ComponentModel.RunWorkerCompletedEventArgs. If you are running under the Visual Studio debugger, the debugger will break at the point in the DoWork event handler where the unhandled exception was raised. If you have more than one BackgroundWorker, you should not reference any of them directly, as this would couple your DoWork event handler to a specific instance of BackgroundWorker. Instead, you should access your BackgroundWorker by casting the sender parameter in your DoWork event handler.
沒有留言:
張貼留言