How do I know if the current thread is a UI thread?

I am working on a user control for UWP and is updating some of its visual effects on certain calls. However, since the .NET core library was biased and the stream classes were greatly reduced, I don’t know how to identify from the method in the user control if the calling thread is a UI thread or not, so it knows whether or not to use the dispatcher to change dependency properties.

Does anyone know how to do this?

EDIT: A dispatcher can functionally "invoke" an asynchronous tone in a user interface thread. However, I really don’t know if it is a good idea to try to call the main thread from the main thread through the dispatcher.If someone has a reason, is it good or bad, this will also help answer the question. If there is no reason not to use the dispatcher in the main thread, then I think that there are no problems.

+7
multithreading c # windows-10 uwp
source share
1 answer

I found a solution ...

CoreDispatcher.HasThreadAccess returns a bool indicating whether you are in the user interface thread or not.

+9
source share

All Articles