SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding Asynchronous I/O in .NET: Benefits, Models, and Patterns

booth avatar
14 diapositives · 377 Views · Jul 26, 2014

Asynchronous I/O in .NET allows background I/O operations to execute while the main application continues to work, enhancing performance and responsiveness. Also known as "Overlapped I/O" in Win32, this model helps improve scalability and throughput while reducing thread overhead. Introduced in .NET 2.0 and expanded in .NET 3.5 and 4.0, developers can utilize the Asynchronous Programming Model (APM) and the Task Parallel Library (TPL) to simplify async operations. This guide covers its benefits, use cases, patterns, and methods for a seamless integration into your applications.

Understanding Asynchronous I/O in .NET: Benefits, Models, and Patterns - slide 1
01 / 14Understanding Asynchronous I/O in .NET: Benefits, Models, and Patterns
1 / 17

Télécharger la présentation

Understanding Asynchronous I/O in .NET: Benefits, Models, and Patterns
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Asynchronous I/O in .NET

  2. What is Async I/O? • 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. What is Async I/O? Synchronous I/O Asynchronous I/O

  4. Why use Async I/O? • Scalability • Throughput • Threads are expensive • Non-blocking UI • Silverlight

  5. Why not Async I/O? • Complexity • Debuggability • Unnecessary?

  6. Asynchronous Programming Model • Standard pattern for async work in .NET 3.5 • Convert:stringDoOperation(int param1, double param2);Into:IAsyncResultBeginDoOperation(int param1, double param2,AsyncCallbackcallback, object state);stringEndDoOperation(IAsyncResultasyncResult); • In WCF, use[OperationContract(AsyncPattern = true)]

  7. Asynchronous Programming Model • 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 Demo

  9. Event-Based Pattern • Introduced in .NET 2.0 to simplify APM • E.g., PictureBox, SoundPlayer, WebClient • MethodAsync methodMethodCompleted eventCancelAsync method • Uses AsyncOperationManager internally

  10. Task Parallel Library • New framework for parallel andasync work in .NET 4.0 • Convert:stringDoOperation(int param1, double param2);Into:Task<string> DoOperation(int param1, double param2);

  11. Task Parallel Library • Two ways to complete asynchronous call: • ContinueWith • Call Task<T>.Result or Task.Wait (blocking)

  12. Task Parallel Library • Wrap existing APM methodIAsyncResultBeginDoOperation(int param1, double param2,AsyncCallbackcallback, object state);stringEndDoOperation(IAsyncResultasyncResult);with FromAsync:Task<string>.Factory.FromAsync(BeginDoOperation, EndDoOperation,int param1, double param2, object state);

  13. Asynchronous I/O with TPL in .NET 4.0 Demo

  14. Where to? • ASP.NET Asynchronous Pages (http://msdn.microsoft.com/en-us/magazine/cc163725.aspx) • IHttpAsyncHandler(http://msdn.microsoft.com/en-us/magazine/cc163463.aspx) • F# Async Workflows (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/ee794896.aspx) • Axum(http://msdn.microsoft.com/en-us/devlabs/dd795202.aspx) • http://github.com/bgrainger/AsyncIoDemo