The Task
class is an improvement over the BackgroundWorker
; it naturally supports nesting (parent/child tasks), uses the new cancellation API, task continuations, etc.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…