Chapter 7. Asynchronous Calls

When a method call is made on an object, the client is typically blocked while the object executes the call, and control returns to the client only when the method completes execution and returns. However, there are quite a few cases in which you want to call methods asynchronously; that is, you want control to return immediately to the client, while the object executes the called method in the background and then somehow lets the client know that the method has completed execution. Such an execution mode is called asynchronous method invocation , and the action is known as an asynchronous call. Asynchronous calls allow you to improve availability, increase throughput and performance, and scale up your application.

In the past, developers often had to handcraft proprietary mechanisms for asynchronously invoking calls on their components. One recurring mechanism was to have the object spin off a worker thread to process the client’s request and immediately return control to the client. The object would later signal the client somehow when the call completed (if the client wanted to know), and the client had to have some way of distinguishing between multiple method completions. These mechanisms were difficult to develop and test, and they forced developers to spend a disproportionate amount of their time reinventing the wheel instead of adding business value to their applications. In addition, such solutions coupled the clients to the objects and were ...

Get Programming .NET Components, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.