When awaiting Dispatcher.RunAsync
the continuation occurs when the work is scheduled, not when the work has completed. How can I await the work completing?
Your question is assuming that you want to schedule (and wait for) work on a UI thread from a background thread.
You'll usually find your code is much cleaner and easier to understand (and it will definitely be more portable) if you have the UI be the "master" and the background threads be the "slaves".
So, instead of having a background thread await
some operation for the UI thread to do (using the awkward and unportable Dispatcher.RunAsync
), you'll have the UI thread await
some operation for the background thread to do (using the portable, made-for-async Task.Run
).