Questions tagged [configureawait]

The ConfigureAwait is a .NET method available for the Task/ValueTask types, that configures an awaiter used to await these awaitables. It has a boolean parameter continueOnCapturedContext that takes the value true to marshal the continuation back to the original context captured, or false to not capture the context.

Documentation:

Articles:

Videos:

52 questions
56
votes
5 answers

When should I use ConfigureAwait(true)?

Has anyone come across a scenario for using ConfigureAwait(true)? Since true is the default option I cannot see when would you ever use it.
NeddySpaghetti
  • 13,187
  • 5
  • 32
  • 61
27
votes
3 answers

Usage of ConfigureAwait in .NET

I've read about ConfigureAwait in various places (including SO questions), and here are my conclusions: ConfigureAwait(true): Runs the rest of the code on the same thread the code before the await was run on. ConfigureAwait(false): Runs the rest of…
Youssef13
  • 3,836
  • 3
  • 24
  • 41
15
votes
1 answer

How to correctly block on async code?

I have tons of code written in following manner: public string SomeSyncOperation(int someArg) { // sync code SomeAsyncOperation(someArg, someOtherArg).ConfigureAwait(false).GetAwaiter().GetResult() // sync code }; Here we have some sync…
Alex Zhukovskiy
  • 9,565
  • 11
  • 75
  • 151
12
votes
3 answers

Why ConfigureAwait(false) does not work while Task.Run() works?

I'm calling an async library method with .ConfigureAwait(false). But, I still end up with deadlock. (I'm using it in ASP.NET controller API) But, if I use the same method wrapped into Task.Run() it works fine. My understanding is, if the libraries…
Krunal Modi
  • 135
  • 1
  • 1
  • 7
8
votes
2 answers

Make AsyncLocal changes propagate to the calling function

DotNet Fiddle link https://dotnetfiddle.net/GqA32R I have the following sample code to demonstrate the async local functionality static AsyncLocal _asyncLocalString = new AsyncLocal(); public static async Task Main() { …
user2133404
  • 1,816
  • 6
  • 34
  • 60
6
votes
1 answer

Still confused on ConfigureAwait(false) used with GetAwaiter and GetResult in C#. Getting a deadlock or method not returning

I have read: http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html and the accepted answer at deadlock even after using ConfigureAwait(false) in Asp.Net flow but am just too dense to see what is going on. I have code: private void…
Dave
  • 8,095
  • 14
  • 56
  • 99
6
votes
1 answer

ConfigureAwait(false) with ADO.Net SQLConnection object

I have started using ConfigureAwait(false) with all the async sql objects. connection.OpenAsync().ConfigureAwait(false); cmd.ExecuteNonQueryAsync().ConfigureAwait(false); But my concern is, Will there be any implications with this approach?. As…
Chandra Mohan
  • 729
  • 2
  • 10
  • 29
6
votes
3 answers

Regex to find missing ConfigureAwait

I have a specific pattern that I want to search for in Visual Studio. Basically, I want to search for lines that contains await, but are missing ConfigureAwait at the end of the statement. I have some patterns that works in regex-testers such as…
Superhubert
  • 141
  • 1
  • 11
5
votes
2 answers

Is ConfigureAwait(true) always get back to the orignial thread, even when the callee method does ConfigureAwait(false) internally?

I was expecting to get back to Thread#1 at location 1.2, but I did not. Is there a way to get back to UI thread after making the async call? Thanks Also I cannot make the top level method async. Not sure if async all the way will solve this issue…
Carol
  • 363
  • 5
  • 16
4
votes
1 answer

The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering

I am working on Dotnet Core Blazor and getting below error while using EventCallBack to bind the parent grid after delete events. Below the code for using Child component @foreach (var employee in Employees) { …
4
votes
1 answer

Can code after 'await' run in different thread in ASP.NET?

I've read here https://blog.stephencleary.com/2009/10/synchronizationcontext-properties.html that ASP.NET applications' execution context does not have specific associated thread. Does it mean code after await will(can) be executed in different…
4
votes
1 answer

ConfigureAwait warning in .net core 3.1

I am developing a server in ASP NET Core 3.1 preview edition and now i see that for all my async methods when calling await i get CA2007 warning (as it is when some task is running asynchronous). Is there any significant change in how the way async…
4
votes
2 answers

Is ConfigureAwait(false) required on all levels of the async chain when no real I/O call is involved?

Implementing a reusable adaptor type of library on top of Azure Document Db Client SDK. The library can run anywhere, not only in an ASP.NET Core web service, but in a command line app, ASP.NET Web Api etc. In this library all methods are async and…
Dogu Arslan
  • 3,292
  • 24
  • 43
4
votes
0 answers

ConfigureAwait in .Net Core console/worker - NOT Asp.Net Core

I have a question about using ConfigureAwait in .NET Core apps. I know that ASP.NET Core has so SynchronizationContext (http://blog.stephencleary.com/2017/03/aspnetcore-synchronization-context.html) but what about other types of apps like console or…
dnf
  • 1,659
  • 2
  • 16
  • 29
4
votes
1 answer

Correct way to return an async task within a non-async method

What is the best practice when returning the following Task: public async Task BuildCommunicationCommand As an object: public Command BuildCommand I have the following: public Command BuildCommand() { return…
James Blackburn
  • 594
  • 4
  • 23
1
2 3 4