1
2
3
4
5
6
1. An asynchronous call is materialized by an object whose class implements the System.IAsyncResult interface. 2. In this example the underlying class is System.Runtime.Remoting.Messaging.AsyncResult.
3. The AsyncResult object is returned by the BeginInvoke() method. 4. It is passed as an argument to the EndInvoke() method in order to identify the asynchronous call.
7
8
1.
WriteSum() method is being called asynchronously by CalDel object using BeginInvoke() method of CalDel delegate 2. That time, along with the parameters, a reference of SumDone() method is also send. 3. Compiler will infer a delegate object of type AsynCallback to reference the SumDone() method 4. As soon as the WriteSum() method call is over, the same thread which was executing WriteSum() method will execute SumDone() method. 5. CalDel delobject = ((AsyncResult)async).AsyncDelegate as CalDel; -> this line indicates that 1. AsyncResult class encapsulates the results of an asynchronous operation on an asynchronous delegate. 2. the IAsyncResult variable ‘async’ is cast to AsynResult class 3. AsyncDelegate propetry of AsyncResult class gets the delegate object on which the asynchronous call was invoked. 4. The retrieved reference is cast to CalDel delegate 6. SumDone() method calls EndInvoke() method 7. A problem can happen as the threads of the pool use to process the asynchronous calls are background threads. 8. So, we must implement an event management mechanism which makes sure that the application does not terminate without completing the execution of the asynchronous calls 9. The IAsyncResult interface represents a synchronization object of a class which derives from WaitHandle, but the object is signaled as soon as the asynchronous process is done and before the callback method is called. 10. Consequently, this object cannot be used to wait for the execution of the callback method.
9
10
11
12
13
14
Reference
15
16