When should you use async / wait, and when not?

Should I use async / await from now on (C # 5) every time I don't require an immediate method result (Task <>) or do I need to run a one-time method (void)?

Should I use it in all cases when I used the Task class in C # 4 and translated the work into Backgroud threads?

Should I use it only when I used asynchronous methods of the .NET Framework?

Confused

I'm basically looking for a simple explanation of when I should use await / async and when not.

+7
source share
1 answer

async / await can be used when you have asynchronous operations. Many operations are naturally asynchronous (for example, input-output); I recommend async for all of these. Other operations are naturally synchronous (for example, computing); I recommend using synchronous methods for them.

You can use Task.Run with async for background work if you need to execute synchronous code asynchronously. I explain on my blog why this is better than BackgroundWorker and asynchronous delegates .

You can also use async to replace other forms of asynchronous processing, such as the IAsyncResult style.

You should use async in any situation where you have an asynchronous operation.

+8
source

All Articles