This question has already been answered:
I do not understand why ConfigureAwait(true) can cause trouble?
Here is a sample code:
private async void button1_Click(object sender, EventArgs e) { int result = DoSomeWorkAsync().Result; // 1 } private async Task<int> DoSomeWorkAsync() { await Task.Delay(100).ConfigureAwait(true); //2 return 1; } Here is its description, but whether there is a typo / curve translation or something I do not understand. Why deadlock ?:
Clicking on the button here leads to deadlock. The UI thread starts a new I / O thread on line “2” and goes to sleep on line “1”, waiting for the completion of work. After the I / O thread finishes executing, the rest of the DoSomeWorkAsync method is passed to the calling (UI) thread for execution. But he is at this time in sleep mode, waiting for the completion of the method. Dedlock.