Asynchronous Programming Design Patterns
Asynchronous operations are typically used to perform tasks that might take a long time to complete, such as opening large files, connecting to remote computers, or querying a database. An asynchronous operation executes in a thread separate from the main application thread. When an application calls methods to perform an operation asynchronously, the application can continue executing while the asynchronous method performs its task.
The .NET Framework provides two design patterns for asynchronous operations:
Asynchronous operations that use IAsyncResult objects.
Asynchronous operations that use events.
The IAsyncResult design pattern allows for a variety of programming models, but is more complex to learn and provides a flexibility that most applications do not require. Where possible, class library designers should implement asynchronous methods using the event-driven model. In some cases the library designer should also implement the IAsyncResult based model.
For documentation on asynchronous operations that use events, see Event-based Asynchronous Pattern Overview.
Asynchronous programming is a feature supported by many areas of the .NET Framework, including:
File IO, Stream IO, Socket IO.
Networking.
Remoting channels (HTTP, TCP) and proxies.
XML Web services created using ASP.NET.
ASP.NET Web Forms.
Message Queuing using the MessageQueue class.
In This Section
Asynchronous Programming Overview
Discusses the IAsyncResult based asynchronous design pattern, which provides a flexible programming model to deal with asynchronous operations.Calling Asynchronous Methods Using IAsyncResult
Provides code examples that demonstrate the various ways applications can detect the end of an asynchronous operation.Asynchronous Programming Using Delegates
Describes calling a synchronous method in an asynchronous manner.Multithreaded Programming with the Event-based Asynchronous Pattern
Describes the Event-based Asynchronous Pattern, which provides an asynchronous programming model that uses events for cross-thread communication.
See Also
Concepts
Reference
Other Resources
C# 3.0 in a Nutshell, Third Edition: A Desktop Quick Reference