16
1

DotNet Asynchornous Programming

Embed Size (px)

DESCRIPTION

DotNet Asynchornous Programming

Citation preview

Page 1: DotNet Asynchornous Programming

1

Page 2: DotNet Asynchornous Programming

2

Page 3: DotNet Asynchornous Programming

3

Page 4: DotNet Asynchornous Programming

4

Page 5: DotNet Asynchornous Programming

5

Page 6: DotNet Asynchornous Programming

6

Page 7: DotNet Asynchornous Programming

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

Page 8: DotNet Asynchornous Programming

8

Page 9: DotNet Asynchornous Programming

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

Page 10: DotNet Asynchornous Programming

10

Page 11: DotNet Asynchornous Programming

11

Page 12: DotNet Asynchornous Programming

12

Page 13: DotNet Asynchornous Programming

13

Page 14: DotNet Asynchornous Programming

14

Page 15: DotNet Asynchornous Programming

Reference

15

Page 16: DotNet Asynchornous Programming

16