Here is the problem I have: I need to make sure an object is instantiated on the UI thread. If it is not, it should throw an exception. But how do I check inside a method whether it is running on the UI thread? Note: I do not want to pass any information into the object's constructor.
The perfect candidate would be the DispatcherSynchronizationContext (WPF implementation of SynchronizationContext) which internally holds a reference to Dispatcher which references the thread it's associated with, but unfortunately that field is private so there is no way for me to access it.