Async/Await Confusion

Ray Turner
Ray Turner used Ask the Experts™
on
I have a Async Function that references a control on the screen.  The control is updated with new information during the running of the function.  Do I place the Await Task.Delay(1) before or after the control is updated?

Btn.text = "One" : Await Task.Delay(1)

or

Await Task.Delay(1) : Btn.text = "One"
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Either one is -technically- valid. You'd have to explain what you're trying to do / why you would want an async delay at this point in your code.

As it stands, it doesn't really make sense to have it in either location, since there's really nothing about setting the button text that has anything to do with async behavior...

If you're trying to to set the text based on some other function/information, then I wouldn't use an arbitrary delay for that. You should probably use an event / callback so that the button text is updated at the appropriate time, regardless if the other update takes 1 second or 30 seconds.
Ray TurnerSenior Consultant

Author

Commented:
Thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial