What thread calls the completed event handler on silverlight WCF calls?

前端 未结 3 2092
甜味超标
甜味超标 2021-01-06 02:45

Assume that I have Silverlight app doing a call to a WCF service:

void DoStuff()
{
    MyProxy proxy = new MyProxy();
    proxy.DoStuffCompleted += DoStuffCo         


        
3条回答
  •  半阙折子戏
    2021-01-06 03:37

    The callback will be invoked on the main thread. Multiple responses will not occur simultaneously. The order of the response events could be unexpected. You may want to use the overload of proxy.DoStuffAsync that accepts "user state" object:

    proxy.DoStuffAsync(object userState)

    This will allow you to send something unique for each call so you can differentiate which response you're dealing with. Remember that if the WCF call returns an error you have no return value - so userState may be the only way to know which call failed (if it matters).

    Update:

    Found some more info (on SO) on how to make it use another thread:

    Silverlight web service callback performance Follow the link there to Tomek's blog for lots more info.

提交回复
热议问题