-
Notifications
You must be signed in to change notification settings - Fork 43
Description
https://learn.microsoft.com/en-us/entra/msal/dotnet/how-to/synchronous-programming#watch-out-for-exceptions-and-deadlocks recommends using ConfigureAwait(false) when synchronously waiting an asynchronous operation:
microsoft-authentication-library-dotnet/msal-dotnet-articles/how-to/synchronous-programming.md
Lines 73 to 77 in 6d02517
| // make sure to have ConfigureAwait(false) to avoid any potential deadlocks | |
| var authResult = builder.ExecuteAsync() | |
| .ConfigureAwait(false) | |
| .GetAwaiter() | |
| .GetResult(); |
However, .ConfigureAwait(false) does not help avoid deadlocks when it is used with .GetAwaiter().GetResult().
In the Task<TResult> class, the ConfigureAwait(bool continueOnCapturedContext) method returns a ConfiguredTaskAwaitable<TResult> value, whose GetAwaiter() method returns a ConfiguredTaskAwaitable<TResult>.ConfiguredTaskAwaiter value, whose m_options field depends on the bool continueOnCapturedContext parameter. The m_options field would then affect the bool IsCompleted property, the void OnCompleted(Action continuation) method, or the void UnsafeOnCompleted(Action continuation) method; but it does not affect the TResult GetResult() method, which is used in the sample.