任务并行库替换BackgroundWorker的? [英] Task parallel library replacement for BackgroundWorker?

查看:276
本文介绍了任务并行库替换BackgroundWorker的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问任务并行库有任何会被认为是在BackgroundWorker的类替代或改善?

Does the task parallel library have anything that would be considered a replacement or improvement over the BackgroundWorker class?

我有一个向导式UI WinForms应用程序,并做一些长时间运行的任务。我希望能够有一个与标准的进度条和取消操作能力,反应灵敏的用户界面。我的BackgroundWorker之前已经这样做了,但如果有可以用来代替一些第三方物流的模式我不知道?

I have a WinForms application with a wizard-style UI, and it does some long-running tasks. I want to be able to have a responsive UI with the standard progress bar and ability to cancel the operation. I've done this before with BackgroundWorker, but I'm wondering if there are some TPL patterns that can be used instead?

推荐答案

工作下课的改进的BackgroundWorker ;它自然地支持嵌套(父/子任务),使用新的API取消,任务延续等。

The Task class is an improvement over the BackgroundWorker; it naturally supports nesting (parent/child tasks), uses the new cancellation API, task continuations, etc.

我有我的博客的一个例子,显示了老<$做事的做事C $ C>的BackgroundWorker 办法和新的工作办法。我确实有需要报告进度任务的小助手类,因为我觉得语法比较尴尬。这个例子包括结果值,错误情况,取消和进度报告。

I have an example on my blog, showing the old BackgroundWorker way of doing things and the new Task way of doing things. I do have a small helper class for tasks that need to report progress, because I find the syntax rather awkward. The example covers result values, error conditions, cancellation, and progress reporting.

这篇关于任务并行库替换BackgroundWorker的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆