I'm working on a user control for UWP and it updates some of its visuals upon certain calls. However, since the core .NET library has been shifted around and the threading classes have been severely cut back, I don't know how to identify from the method in the user control if the calling thread is the UI thread or not so it knows whether or not to use the dispatcher to change a dependency property.
Anyone know how to do this?
EDIT: The dispatcher functionally can be "invoked" async fine on the UI thread - however, I really don't know if this is a good idea - to try to invoke on the main thread from the main thread via the dispatcher. If anyone has a reason this is fine or bad, that would also contribute to answering the question. If there's no reason to not use the dispatcher on the main thread, then I guess there's no problem.
RunAsync()
is fine. Frankly, IMHO it would be better to design the code so that property updates are done only from the appropriate thread. It is generally easy to stay on the UI thread, except for background operations, pushing updates back to the UI thread. But if you find yourself in a situation where that can't work, just calling theRunAsync()
or similar will work. See my related rant here: blogs.msmvps.com/duniho/2008/09/12/… – Redden