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:- 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.
- 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:
Post a Comment