views:

53

answers:

3

I tried creating one, but the BackgroundWorker in Window1 couldn't access the ProgressBar in Window2 once the reportProgress was activated, because "The calling thread cannot access this object because a different thread owns it".

Seems there's a lower level thread model I could use, but it also seems a lot more complicated.

A: 

You need to look into Delegates

Filip Ekberg
Except the delegate will also execute on the background thread, leaving the OP with the same problem.
slugster
+1  A: 

In WPF, UI controls and properties may only be activated from the UI thread. In order to change the progress bar's value from a different thread, you can add a command to the GUI thread's dispatcher queue. You can do this by passing a delegate to the Dispatcher.Invoke() method. See the article at http://msdn.microsoft.com/en-us/magazine/cc163328.aspx for more details.

dosendoc
+1  A: 

You just need to get the prograssbar disptacher

You can access the progressbar with

Window2.prograssbar.Dispatcher.Invoke(
    () => /*the code for modifying the progressbar*/ );
Svetlozar Angelov
this page also helped me http://www.switchonthecode.com/tutorials/working-with-the-wpf-dispatcher
zxcvbnm