I’m using web refernce call in new working thread in my application as follow:
Thread callRunner = new Thread(delegate()
{ _mediator.IncomingCallDetails(phoneNumber); });
callRunner.Start() ;
the _mediator calls the web refernce and replay to the caller in event as follow:
void IncomingCallComplited(IncomingCallEventArg args)
{
Caller = args.Caller;
Lodgers = args.Lodgers;
PreviousMissions = args.PreviousMissions;
}
Caller ,Lodgers and PreviousMissions are properties of an object that bind to GUI element,as for now the binding works fine and I can see the values from the web reference in screen my question is should I use Dispatcher in the event or in any other phase ? and if I do can someone please explain why?
Thanks
Eran
Actually, the binding system takes care of that for you, so you don’t need to explicitly marshal the call to the UI thread. However, this behavior is not documented (unless I missed it), so I’m not sure you should rely on it…
Also, note that although the
PropertyChangedevent is correctly marshalled across threads by the binding system, theCollectionChangedevent is not. So if you’re adding data from another thread to anObservableCollectionthat is bound to the UI, you need to callDispatcher.Invoke. Or you can use this customObservableCollectionclass, which raises theCollectionChangedevent on the UI thread