I was doing some coding in ASP.NET when I came across this:
protected async void someButtonClickHandler(...)
{
if(await blah)
doSomething();
else
doSomethingElse();
}
After asking this question I got a better understanding of how async
/await
works. But then it struck me is it safe to use async
/await
in the manner shown above?
I mean after calling await blah
the caller continues execution. Which means it might render the response back to client before await blah
completes. Is this right? And if this is the case what happens to doSomething()
/doSomethingElse()
. Will they ever be executed? If they're executed does the user see the effects of their changes?
In my case these methods change some data displayed to the user, but I'd also like to know what would happen in the general case.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…