MSDN Notes: Implementing the CLR Asynchronous Programming Model (Jeffrey Richter)
Source: http://msdn.microsoft.com/msdnmag/issues/07/03/ConcurrentAffairs/
1. Introduction
a. For applications that require interaction with IO, the answer is often to write into the solution more threads – this still incurs an overhead, however, in terms of the operating system resources needed to spawn and manage threads.
b. The better solution, according to this article, is to use the CLR’s Asynchronous Programming Model (APM) in lieu of the a more heavily threaded application.
c. There are four main reasons, according to this article, why you would write a class that implements the APM.
i. You’re building a class that directly interacts with hardware,
ii. You might be building an abstraction layer atop a class or code base that already talks to hardware,
iii. You may have long-running methods in your class,
iv. You might be wrapping non-asynchronous Win32 functions.
2. The heart of the APM: IAsyncResult
a. Any class implementing APM has a Begin/End method (ex: BeginRead/EndRead) pair of methods. The Begin version must create and return an Iasyncresult object that is the center of APM model.
i. The object can be queried for the status of the asynchronous operation and is used to determine the result when the operation is completed.
b. IAsyncResult has a property – a wait handle – that is actually ineffecient to use and so ought to be avoided if at all possible (many asynchronous operations will have a callback anyway, signalling the end to the operation).