Just a confirmation if I got it right because I couldn't find a definitive answer to this:
private async void button_click()
{
await DoWork();
Textbox.Text = "Hello World";
}
private async void button_click()
{
var ret = await DoWork();
Textbox.Text = "Hello World";
}
private async Task<int> DoWork()
{
int ret = 0;
ret = await WriteToDiskAsync();
return ret;
}
If I assign the return value of the async method to a variable, I'm 100% sure that the Textbox.Text assignment is done after DoWork()
completes, even if what follows does not use the ret variable. While in the first example is uncertain if Textbox.Text assignment is done after DoWork()
completes, because the UI thread is not suspended and the flow continues, so depending on the amount of work of DoWork()
and the scheduler anything could happen.
I thought await meant what it means in the natural language...wait, but is not like that.