I have a small project - WinForms
On .net frameWork - just a small test :
private void button9_Click(object sender, EventArgs e)
{
string text = GetTitleAsync().Result;
button9.Text = text;
}
private async Task<string> GetTitleAsync()
{
await Task.Delay(3000);
return "Hello!";
}
As I ran the application ,
Clicking the button: "button9" - caused a dead lock,
(since the thread was hung on the ".result" )
Writing GetTitleAsync() this way:
private async Task<string> GetTitleAsync()
{
await Task.Delay(3000).ConfigureAwait(false);
return "Hello!";
}
solved the deadlock - and the application ran ok.
But I don't understand how ?
I would have expected, that using ".ConfigureAwait(false)" would cause a
situation in which :
"button9.Text = text;" is executed on a different thread than
the one, on which the UI was created,
and an excpetion would be throwed !
but it works excellent !
how??
question from:
https://stackoverflow.com/questions/65933864/configureawait-ui-await-async 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…