ConfigureAwait
In this page:
ConfigureAwait
ConfigureAwait(false) tells await not to try to resume execution back on the original synchronization context (like a UI thread), which can improve performance and avoid deadlocks in library code. In console apps and modern ASP.NET Core there's no special context to return to, so it makes less practical difference there. It's mainly a library-authoring best practice rather than something application code needs everywhere.
Note: Use ConfigureAwait(false) in reusable library code that has no reason to depend on a specific UI thread.
Example: ConfigureAwait
using System;
using System.Threading.Tasks;
class Program
{
static async Task<int> LoadDataAsync()
{
await Task.Delay(50).ConfigureAwait(false);
return 7;
}
static async Task Main(string[] args)
{
int value = await LoadDataAsync();
Console.WriteLine(value);
}
}
Login to try C/C++/Java/PHP code in the editor
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: