CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Thursday, October 05, 2006

How to write .NET Asynchronous Code Blocks

How to write .NET Asynchronous Code Blocks

Index

  1. Introduction
  2. Using Asynchronous Code Blocks
  3. Handling Exceptions in Asynchronous Code Blocks
  4. WinForms and Asynchronous Code Blocks
  5. Points of Interest
  6. Software Usage
  7. History

1. Introduction

Asynchronous Code Blocks, shortly called as ACB hereafter in this article, is a technique and a companion library for C# 2.0 applications, to run portions of a method code asynchronously without explicitly using threads, delegate type declarations, thread handler methods, synchronization objects, and all those complex stuff associated with asynchronous multithreaded programming.

Below is the summary of the features offered by the ACB library:

  1. Run portions of the method code defined using anonymous methods asynchronously.
  2. Asynchronous execution of the ACB can be scheduled on an AppDomain-wide ManagedIOCP ThreadPool, or a user-created ManagedIOCP ThreadPool instance.
  3. Wait on completion of the ACB infinitely, or for specified time (milliseconds).
  4. Wait on completion of execution of all the ACBs in a list of ACBs. The features 3 and 4 allow an application to wait on all the pending ACBs during its closure.
  5. Wait on completion of execution of any one of the ACBs in a list of ACBs.
  6. Get notified about the execution completion of an asynchronous code block using a delegate.
  7. Make the execution of an ACB dependent on the completion of execution of another ACB. For instance, if ACB Y is dependent on ACB X, ACB Y will start executing only after ACB X has completed its execution.
  8. Make the execution of an ACB dependent on the completion of execution of all the ACBs in a list of ACBs.

As you already observed, ACB depends on “Anonymous Methods” in C# 2.0 and the ManagedIOCP based Task Framework and the ThreadPool class from the Sonic.Net library. The Sonic.Net library is my own library that I created as part of my ManagedIOCP articles on CodeProject. Below are the links to my articles on “Anonymous Methods” and “ManagedIOCP”.

How to write .NET Asynchronous Code Blocks

Post a Comment