Wasn't it .NET 4.0 TPL that made APM, EAP and BackgroundWorker asynchronous patterns obsolete?

前端 未结 3 1426
生来不讨喜
生来不讨喜 2020-12-24 02:54

I have 2 kinds of C# WPF app projects:

  • based on .NET 4.0 that I cannot migrate to .NET 4.5
  • based on .NET 4.0 that I can migrate to .NET 4.5
  • <
3条回答
  •  攒了一身酷
    2020-12-24 03:34

    I consider these patterns (APM, EAP, and BGW in particular) obsolete in .NET 4.5. The combination of async with Task.Run is superior to BGW in every way. In fact, I just started a series on my blog where I will compare BGW to Task.Run and show how it's more cumbersome in every situation; there are some situations where it's just slightly more cumbersome, but there are other situations where it's much more cumbersome.

    Now, whether they're obsolete in .NET 4.0 is another question entirely. From your other posts, you're talking about developing for .NET 4.0 with VS2010, so the backport Microsoft.Bcl.Async isn't an option. In that case, neither APM nor EAP can be considered obsolete IMO. On this platform, you can consider Task.Factory.StartNew as an alternative to BGW but BGW does have some advantages when it comes to progress reporting and automatic thread marshaling of its progress and completion events.

    Update: I did recently update an old blog post of mine where I discuss various implementations of background operations. In that post, when I talk about "Tasks (Async Methods)", I mean using Task with all the .NET 4.5 async support, Task.Run, etc. The "Tasks (Task Parallel Library)" section is evaluating Task as it existed in .NET 4.0.

提交回复
热议问题