The title says it all. I would like to be able to simply detect if work is being executed on the UI thread. Also, if the method is not running on the UI/main thread, can I determine what other thread that it might be? I would like to use this information for debugging purposes. Thanks!
Asked
Active
Viewed 273 times
-7
-
Look at [this SO Question](https://stackoverflow.com/questions/815929/how-can-a-method-know-if-its-running-on-the-ui-thread) – Icemanind Nov 09 '18 at 12:40
1 Answers
-1
In a UWP app, you can check and store the value of the Environment.CurrentManagedThreadId property when your app starts and then compare the current value of the same property with the stored value to determine whether you are on the same thread.
Or use the CoreDispatcher.HasThreadAccess property to determine whether the current thread can safely update the UI.

mm8
- 163,881
- 10
- 57
- 88