Skip to content

Instantly share code, notes, and snippets.

@pedroreys
Created April 2, 2013 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroreys/5292915 to your computer and use it in GitHub Desktop.
Save pedroreys/5292915 to your computer and use it in GitHub Desktop.
find the potential bug
public static class Foo
{
private static async Task DelayAsync()
{
await Task.Delay(1000);
}
public static void Test()
{
var delayTask = DelayAsync();
delayTask.Wait();
}
}
@juanplopes
Copy link

If this is running in a synchronization context that ensures continuations run on the same thread (WinForms, for example), delayTask.Wait would hang the UI thread forever, not allowing the await Task.Delay to ever return.

This would cause a deadlock. I guess.

@pedroreys
Copy link
Author

Nailed it, @juanplopes!

By the way, got the example from here: http://msdn.microsoft.com/en-us/magazine/jj991977.aspx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment