Is there any way to get the gui thread dispatcher when you have no reference to any elements..
+2
A:
Use the Dispatcher.CurrentDispatcher
property.
Note that you need to get it from the UI thread.
SLaks
2010-04-18 16:57:25
so there is no way if you dont have or had a reference to a gui object?
Petoj
2010-04-18 17:01:56
You can use that static property without any references to UI objects, as long as you're on the UI _thread_.
SLaks
2010-04-18 17:03:47
well in this case im not 100% sure that im on the UI Thread...
Petoj
2010-04-18 17:08:24
If you're not sure, you probably are. (Are you using the `Thread` or `ThreadPool` classes?
SLaks
2010-04-18 17:09:27
yes in some cases
Petoj
2010-04-18 17:11:55
Is your code running there?
SLaks
2010-04-18 17:47:08
yes its running on a separate thread but not when the tread is started?
Petoj
2010-04-18 17:50:48
Then you'll need to get `CurrentDispatcher` in the UI thread and pass it to the other thread.
SLaks
2010-04-18 17:53:54
+2
A:
You can grab the UI Dispatcher from the static application instance: Application.Current.Dispatcher
You may want to check Application.Current
for null first, as it can be cleared during a shutdown sequence.
Abe Heidebrecht
2010-04-19 21:54:36