✅ Async PushButton Functions
What is the proper way to handle FileIO asynchronously?
I have a Utility class that performs various functions, one in particular:
The compiler complains at the await Utils.PickPhoto();
If I remove it, and satisfy the complier errors no result is returned.
Is my setup correct?
What am I doing wrong?
Thank you in advance.
9 Replies
You should have
This assumes result is never null
Also
Is not right, when you await a
PickPhoto
the return type is not Task<string>
but just string
Let me give it a try.
And I will test for null and return string.Empty if so.
You should not
GetAwaiter().GetResult()
do that at allThat worked rather well 🙂
Awesome!
The general rule of thumb, when you see an async method (a method that returns Task) and you need it's result
use
await
it instead of task.GetAwaiter().GetResult();
To confirm what I have now is:
What about the UI thread and controls being modified. I do not need any protection?
You don't need to, when you
await
the method, it continues on the calling thread which would be the UI threadExcellent. Thank you so much again.
No problem!