Skip to main content
3 of 5
Added important note about ConfigureAwait

The way to handle this pattern is to ensure that all I/O is asynchronous. Synchronous I/O methods cause the current thread to block while it waits for a response from the I/O destination (network, file-system, etc).

Another thing to consider is that await should be used when you need a return value or when you need the awaited code to finish before doing something else. If you don't need either of those things, you can "fire and forget" your async method with Task.Run.

So, for the most efficient use of computing resources, if RemoveRoles does any I/O, it should become await RemoveRolesAsync and the I/O methods called by RemoveRolesAsync should also be async (and possibly awaited).

If performance is not your utmost concern, then it's fine to do some synchronous I/O on an async thread. It is a technical debt though. (In this case, the first async method should be called with ConfigureAwait if possible (as explained in the best practices article below.))

Here's a more in-depth look at the best practices - https://msdn.microsoft.com/en-us/magazine/jj991977.aspx