异步/等待 vs BackgroundWorker [英] Async/await vs BackgroundWorker

查看:31
本文介绍了异步/等待 vs BackgroundWorker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这几天我测试了 .net 4.5 和 c#5 的新特性.

In the past few days I have tested the new features of .net 4.5 and c# 5.

我喜欢它的新 async/await 功能.早些时候我使用 BackgroundWorker使用响应式 UI 在后台处理更长的进程.

I like its new async/await features. Earlier I had used BackgroundWorker to handle longer processes in the background with responsive UI.

我的问题是:在拥有这些不错的新功能之后,我应该何时使用 async/await 以及何时使用 BackgroundWorker?两者的常见场景是什么?

My question is: after having these nice new features, when should I use async/await and when a BackgroundWorker? Which are the common scenarios for both?

推荐答案

async/await 旨在替换诸如 BackgroundWorker 之类的结构.如果您愿意,您当然可以使用它,但您应该能够使用 async/await 以及其他一些 TPL 工具来处理所有存在的问题.

async/await is designed to replace constructs such as the BackgroundWorker. While you certainly can use it if you want to, you should be able to use async/await, along with a few other TPL tools, to handle everything that's out there.

既然两者都有效,那归结为您何时使用的个人喜好.什么对来说更快?什么对更容易理解?

Since both work, it comes down to personal preference as to which you use when. What is quicker for you? What is easier for you to understand?

这篇关于异步/等待 vs BackgroundWorker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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