Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

Consider ConfigureAwait() for API calls #4

Open
BillWagner opened this issue Nov 19, 2014 · 5 comments
Open

Consider ConfigureAwait() for API calls #4

BillWagner opened this issue Nov 19, 2014 · 5 comments

Comments

@BillWagner
Copy link

As already written here DotNetAnalyzers/Proposals#26 this is tricky, but an important item to try and catch.

@sharwell
Copy link
Member

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:

  • When two await expressions appear in sequence, the first one can almost always use ConfigureAwait(false). Edit: I misunderstood the behavior of continuations when I made this statement.

@tugberkugurlu
Copy link

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

you mean the second one?

@sharwell
Copy link
Member

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
Copy link

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
Copy link

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants