Share via


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

See Also

Concepts

Asynchronous File I/O

Reference

AsyncCallback

IAsyncResult

Delegate

AsyncOperationManager

BackgroundWorker

Other Resources

C# 3.0 in a Nutshell, Third Edition: A Desktop Quick Reference