Thursday, September 11, 2014

Task.Run Etiquette and Proper Usage

Aha, here is the answer I've been looking for!

In general, do not use Task.Run in the implementation of the method; instead, use Task.Run to call the method. There are two reasons for this guideline:
  1. Consumers of your code assume that if a method has an asynchronous signature, then it will act truly asynchronously. Faking asynchronicity by just doing synchronous work on a background thread is surprising behavior.
  2. If your code is ever used on ASP.NET, a fake-asynchronous method leads developers down the wrong path. The goal of async on the server side is scalability, and fake-asynchronous methods are lessscalable than just using synchronous methods.

No comments: