Consider this simple async
method:
private static async Task<int> foo()
{
await Task.Delay(1500);
return 1;
}
If I do the following in a WinForm
application, as I expect, it deadlocks
private void Form1_Load(object sender, EventArgs e)
{
var fooTask = foo();
fooTask.Wait();
}
However, if I do the same in a ConsoleApplication
it works (doesn't deadlock)
static void Main(string[] args)
{
var fooTask = foo();
fooTask.Wait();
}
Why this happens? Shouldn't the Task
be unable to continue because the context thread is "blocked"?