views:

25

answers:

1

Hi,

I'm hacking away at some code which seems to have been started, at least in theory, as an MVVM project in Expression Blend, by my predecessor at this company.

I've got a thread running in the background, which is running some operations on items as they happen. In order to prevent any clashes, I've also got that thread running any operations my users call for.

Once those operations are completed, I'd like to bring up a MessageBox to give a summary of the user-initiated operations, but now that they're running off in their own thread, the finishedProcessing event handler is now running on the background thread instead of the interface thread and it's causing my MessageBoxes to appear non-modally.

Back in the WinForms days, I'd have handled that using InvokeRequired, Invoke and a Delegate. I've read that this has been replaced by something called "Dispatcher", but the ViewModel class I'm using doesn't seem to have a Dispatcher object.

The "thisViewModel" class I'm using inherits a class called "WorkspaceViewModel", which inherits "ViewModelBase", both of which look generated to me...

Sorry if all of this is a bit vague, but I didn't write the code. Anyhow, does anyone know where I can link up to this "Dispatcher" from here?

A: 

Have a look at this, http://www.codeproject.com/KB/WPF/MessageBoxInMVVM.aspx

bjoshi
That seems to be an article on how to make sure a call for a MessageBox doesn't lock up a series of unit tests, by encapsulating the MessageBox into a container, and then having a separate container for use in the unit tests. Interesting but nothing to do with the Dispatcher or Invoking delegates, as far as I can see...
Frosty840
ViewModelBase has should have another constructor which takes Dispatcher, so that the view model when created can be passed with user control's dispatcher.
bjoshi
Well, making that change solves the problem, but it doesn't really have anything to do with your link... Thanks anyway, I guess.
Frosty840