开发者

multi threading wpf

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 ,Lod开发者_JAVA技巧gers 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 PropertyChanged event is correctly marshalled across threads by the binding system, the CollectionChanged event is not. So if you're adding data from another thread to an ObservableCollection that is bound to the UI, you need to call Dispatcher.Invoke. Or you can use this custom ObservableCollection class, which raises the CollectionChanged event on the UI thread

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜