In the 'old' times it was very easy to track which method is hanging: just go to debugger, hit 'pause' button and go through stack traces.
Now however, if the problem is in the async method, this approach does not work - since the next piece of code to execute is buried somewhere in the continuation tasks (technically it does not even hang)... Is there a way for such easy debugging with tasks?
public partial class MainWindow : Window
private async void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
MessageBox.Show("Holy war complete!");
public static async Task DoHolyWar()
public static async Task DoHolyWarComplicatedDetails()
public static Task BurnHeretics()
var tcs = new TaskCompletionSource<object>();
// we should have done this, but we forgot
In situations like this, what you can do is go to the debug dropdown menu, go to Windows, and choose the "Tasks" window (The default short cut key combo is "Ctrl+D, K").
This can give you a clue on what tasks are hanging.
Look for tasks that have abnormally long
Duration values, that is a indication that something happened to the task and it is not completing. If you double click on the line it will take you to the await that is hung.
I don't know for sure why
await BurnHeretics(); does not show up in the list for me, but I do know that this window will behave differently depending on your OS version because it relies on OS features to track some types of tasks. But at minimum this will show you that
await DoHolyWarComplicatedDetails(); is hanging which will lead you to inspect
DoHolyWarComplicatedDetails() which will lead you to inspect
BurnHeretics(); which will lead you to your bug that is causing the hang.