December 2019
Intermediate to advanced
346 pages
9h 8m
English
We could have avoided deadlock in the preceding code example by completely skipping the use of SynchronizationContext:
private async Task DelayAsync(){await Task.Delay(2000);}public void Deadlock(){var task = DelayAsync().ConfigureAwait(false);task.Wait();}
When we use ConfigureAwait(false), the method is awaited. When the await completes, the processor tries to execute the rest of the async method within the thread pool context. The method is able to complete with no issues since there are no blocking contexts. The method completes its returned task, and there's no deadlock.
We have come to the end of this chapter. Let's now see all we have learned!
Read now
Unlock full access