title: Silverlight - limit application to one WCF call at a time
body: <p>Silverlight can only send a certain number of simultaneous WCF requests at a time. I am trying to serialize the requests that a particular section of my application is performing because I don't need them to run concurrently.</p>
  
  <p>The problem is as follows (summary below): 
  "WCF proxies in Silverlight applications use the SynchronizationContext of the thread from which the web service call is initiated to schedule the invocation of the async event handler when the response is received. When the web service call is initiated from the UI thread of a Silverlight application, the async event handler code will also execute on the UI thread."
  <a href="http://tomasz.janczuk.org/2009/08/improving-performance-of-concurrent-wcf.html" rel="nofollow">http://tomasz.janczuk.org/2009/08/improving-performance-of-concurrent-wcf.html</a></p>
  
  <p>summary: basically, if you block the thread that is calling the async method, it will never get called.</p>
  
  <p>I can't figure out the right model of threading this such which would give me what I want in a reasonable way.</p>
  
  <p>My only other requirement is that I don't want the UI thread to block.</p>
  
  <p>As far as I can see, what <em>should</em> work is if the UI thread has a worker thread which queues up the calls as <code>Action</code> delegates, then uses an <code>AutoResetEvent</code> to execute a task one at a time in yet <em>another</em> worker thread. There are two problems:
  1) The thread that calls async can't block, because then async will never get called. In fact, if you put that thread into a wait loop, I've noticed it doesn't get called either
  2) You need a way to signal from the completed method of the async call that it is done.</p>
  
  <p>Sorry that was so long, thanks for reading. Any ideas?</p>