Presentation is loading. Please wait.

Presentation is loading. Please wait.

 Executing I/O in the background, allowing foreground work to proceed  I/O executes and completes in parallel with, and independent of, the application.

Similar presentations


Presentation on theme: " Executing I/O in the background, allowing foreground work to proceed  I/O executes and completes in parallel with, and independent of, the application."— Presentation transcript:

1

2  Executing I/O in the background, allowing foreground work to proceed  I/O executes and completes in parallel with, and independent of, the application that initiated it  Called “Overlapped I/O” in Win32

3 Start I/O Blocked Start I/O Blocked Start I/O Blocked Process Synchronous I/O Asynchronous I/O Start I/O Blocked Process Background I/O

4  Scalability  Throughput  Threads are expensive  Non-blocking UI  Silverlight

5  Complexity  Debuggability  Unnecessary?

6  Standard pattern for async work in.NET 3.5  Convert: string DoOperation(int param1, double param2); Into: IAsyncResult BeginDoOperation(int param1, double param2, AsyncCallback callback, object state); string EndDoOperation(IAsyncResult asyncResult);  In WCF, use [OperationContract(AsyncPattern = true)]

7  Four ways to complete asynchronous call:  Supply an AsyncCallback  Poll IAsyncResult.IsCompleted  Wait on IAsyncResult.AsyncWaitHandle (blocking)  Call EndXxx method (blocking)  Always call EndXxx method!

8 Asynchronous I/O with APM in.NET 3.5

9  Introduced in.NET 2.0 to simplify APM  E.g., PictureBox, SoundPlayer, WebClient  MethodAsync method MethodCompleted event CancelAsync method  Uses AsyncOperationManager internally

10  New framework for parallel and async work in.NET 4.0  Convert: string DoOperation(int param1, double param2); Into: Task DoOperation(int param1, double param2);

11  Two ways to complete asynchronous call:  ContinueWith  Call Task.Result or Task.Wait (blocking)

12  Wrap existing APM method IAsyncResult BeginDoOperation(int param1, double param2, AsyncCallback callback, object state); string EndDoOperation(IAsyncResult asyncResult); with FromAsync: Task.Factory.FromAsync(BeginDoOperation, EndDoOperation, int param1, double param2, object state);

13 Asynchronous I/O with TPL in.NET 4.0

14  ASP.NET Asynchronous Pages (http://msdn.microsoft.com/en-us/magazine/cc aspx)http://msdn.microsoft.com/en-us/magazine/cc aspx  IHttpAsyncHandler (http://msdn.microsoft.com/en-us/magazine/cc aspx)http://msdn.microsoft.com/en-us/magazine/cc aspx  F# Async Workflows (http://blogs.msdn.com/dsyme/archive/2007/10/11/introducing-f-asynchronous- workflows.aspx)http://blogs.msdn.com/dsyme/archive/2007/10/11/introducing-f-asynchronous- workflows.aspx  Reactive Extensions for.NET (http://msdn.microsoft.com/en-us/devlabs/ee aspx)http://msdn.microsoft.com/en-us/devlabs/ee aspx  Axum (http://msdn.microsoft.com/en-us/devlabs/dd aspx)http://msdn.microsoft.com/en-us/devlabs/dd aspx 


Download ppt " Executing I/O in the background, allowing foreground work to proceed  I/O executes and completes in parallel with, and independent of, the application."

Similar presentations


Ads by Google