Sorry, but I am not agree with Chris Schmich.
You can see that the VerifyCalledOnUIThread()
appears in the DataModel
. Actually the purposes is To Veryfy the DataModel (not the control) only accessed from UI Thread. Yes WPF/SilverLight UI is not cross thread safe, but in this case that was't the real reason.
The fact is if you bind something (datamodel/viewmodel) to WPF/SilverLight UI and you access it from different thread other then UI thread, then you will get uninformative exception. Trouble shooting this error is verry hard because Exception thrown didn't give any clue.
I give you example about that:
//pass model to datacontex and bind it
mycontrol.DataContext = myModel;
//myThreadedService is an assynchronous service
//done ini different thread.
//so ServiceDone will call myModel.Complete from different thread
//system will crash unexpectedly without enough clue
myThreadedService.ServiceDone += (s, e) => { myModel.Complete = true; }
myThreadedService.CallService();
So, i think you understand now why this piece of code should be there:
Debug.Assert(Dispatcher.CurrentDispatcher == this.Dispatcher,
"Call must be made on UI thread.");
This code will give a clue when you accessing DataModel from different thread.