I have a simple Winforms application with a button on it. Using EF 6.1.1 code first, if I use .ToListAsync on a query it will freeze the form until the result came back from the SQL Server.
private async void button1_Click(object sender, EventArgs e)
{
using( var context = new MyEFContext() )
{
var result = await context.MyTable.ToListAsync();
MessageBox.Show(result.Count);
}
}
If I put the .ToListAsync() call in a different synchronization context say by adding await Task.Delay(1).ConfigureAwaiter(false)
before it, it works as it should be.
Does anybody know what I'm missing here? Why is it like this?