As I understand it, this is a replacement for the SynchronizationContext web forms in the MVC world to ensure that the thread processing the request will wait for all asynchronous operations to complete before they return. Consider the following code:
public ViewResult Index() { Task.Factory.StartNew(() => { // web service call here }); return View(); }
Index() works in the main (HTTP request) stream. StartNew() will capture a thread from ThreadPool , which launches a web service call delegate on it and immediately returns to the main thread. The main thread immediately returns (the view) and finishes processing the request (somewhere down the stack in the ASP.NET runtime). But the second thread is still working (most likely, waiting for the completion of I / O), but this does not make sense - no one is waiting for it to use its result.
This is what the SynchronizationContext for web forms. It saves the internal counter of all outstanding asynchronous calls and waits for them all before returning from the main thread (i.e. the counter will decrease to zero). AsyncManager does the same, but you increment / decrement the counter manually. If you are interested in the concept of SynchronizationContext (this is not easy to understand), I would recommend a series of articles by Mike Peretz . This option will also be very useful.
Usercontrol
source share