BackgroundWorker and Threads

后端 未结 6 2254
渐次进展
渐次进展 2021-02-15 11:19

What are the pros and cons in using the either for achieving a given task.

The million dollar question is which one to use and when?

Many Thanks.

6条回答
  •  [愿得一人]
    2021-02-15 11:32

    Have a look at this great threading overview:

    [The BackgroundWorker] provides the following features:

    • A "cancel" flag for signaling a worker to end without using Abort

    • A standard protocol for reporting progress, completion and cancellation

    • An implementation of IComponent allowing it be sited in the Visual Studio Designer Exception handling on the worker thread

    • The ability to update Windows Forms and WPF controls in response to worker progress or completion.

    The last two features are particularly useful – it means you don't have to include a try/catch block in your worker method, and can update Windows Forms and WPF controls without needing to call Control.Invoke.

提交回复
热议问题