I want to create a thread with a Dispatcher and then, from another thread, use that dispatcher to queue work with different priorities. i.e.
var dispatcher = GetNewThreadDispatcher();
dispatcher.BeginInvoke(longRunningTask1, DispatcherPriority.Normal);
dispatcher.BeginInvoke(longRunningTask2, DispatcherPriority.Background);
dispatcher.BeginInvoke(longRunningTask3, DispatcherPriority.Normal);
In this case, the background thread would perform longRunningTask1, then longRunningTask2, longRunningTask3. I’m having difficulty creating a clean GetNewThreadDispatcher(), any help?
You can try to create new background thread ( http://msdn.microsoft.com/en-us/library/7a2f3ay4(v=vs.90).aspx) and get
Dispatcherfor it:Some edits:
You need to execute
Dispatcher dispatcher=Dispatcher.CurrentDispatcherorDispatcher.RuninsideOnThreadStart. But interesting thing: after executedispatcherisnullbut after executedispatcheris fillingadded:
this code working in my test wpf app but i am not expert in multithreading. May be someone will correct me or add some info to this reply.