DotNetAnalyzers / AsyncUsageAnalyzers

Now superseded by Microsoft/vs-threading
https://github.com/Microsoft/vs-threading
Other
121 stars 18 forks source link

Consider ConfigureAwait() for API calls #4

Open BillWagner opened 9 years ago

BillWagner commented 9 years ago

As already written here https://github.com/DotNetAnalyzers/Proposals/issues/26 this is tricky, but an important item to try and catch.

sharwell commented 9 years ago

This could be available as a refactoring operation for any await expression. In addition some cases may be identified with a diagnostic. Here is my list of [currently one] such case:

tugberkugurlu commented 9 years ago

When two await expressions appear in sequence, the first one can almost always use ConfigureAwait(false).

you mean the second one?

sharwell commented 9 years ago

No, the first one. If all you are going to do is start a new task, why would you need to do so from a particular thread?

tugberkugurlu commented 9 years ago

AFAIK, threading and asynchronous programming is not 100% related but I could be wrong. If you do the following under any context which has SynchronizationContext (e.g. ASP.NET, WPF, etc.), I'm sure you will get into trouble (assuming that GetAsync method will perform asynchronously):

var foo = await _httpClient.GetAsync("http://localhost:5000").ConfigureAwait(false);

// ... other code which is UI related if under WPF or HttpContext related code if under ASP.NET
tugberkugurlu commented 9 years ago

More info: