views:

938

answers:

2

Why do the Silerlight-generated WCF proxy class(es) offer only async calls?

There are cases where I don't really need the async pattern (for example in a BackgroundWorker)

EDIT : Sometimes I need to process the results of two WCF calls. It would have been much simpler if I could have waited (the business of the app allows that) for both calls to end and then process.. but noooo.... async! :P

+6  A: 

As I understand it, the aim here is to make it hard for people to do the wrong thing (sync. IO from the UI). If you are using the WCF classes, you'll probably have to live with it.

Marc Gravell
+1 prevent the Silverlight dev from shooting themselves in the foot all too badly :-)
marc_s
Good point!
Andrei Rinea
Silverlight only lets you make network calls on the UI Thread (not sure this may be a browser restriction as well). Therefore sync IO would lock up the browser, bad thing.
Nigel Sampson
"prevent the Silverlight dev from shooting themselves in the foot"; now I have to wait for 4 async requests to gather data and present it and I can't shoot myself in the foot. The runtime has shot me in the foot. Convenient..
Andrei Rinea
You (or rather, your user) has to wait for them either way. How exactly has the runtime offended you?
Marc Gravell
+3  A: 

There's actually a technical reason you can't do sync calls, at least from the 'main' browser thread, which is that the browser invokes all the plug-in API calls on the same thread, so if SL were to block that thread while waiting for the network callback, the network callback wouldn't get through and the app would deadlock. That said, the sync API would work fine if initiated from a different thread -- ie, if the application first does a QueueUserWorkItem to get off the browser thread -- but we felt it would be confusing to offer the sync option and have it only work some of the time.

alexdej