Saturday, March 31, 2012

Asynchronous method calling using events and delegates - CodeProject®

Introduction to Article

In this article, we’ll elaborate how to call methods asynchronously. As we all know, delegates are used to call methods asynchronously, but here we’ll combine asynchronous function calling and the event handling concept for achieving Asynchronous Processing. To avoid confusion, let’s define what we are going to do in this example shortly.

We’ll develop a Task class that contains an IterateFile() method and three events – StatusEvent, Complete, ProgressChanged. StatusEvent will keep track of the file status during file processing. The Complete event is raised when file processing completes. The ProgressChanged event is raised when the iteration completes.
We’ll also develop the FileProcessing class that contains the Processing() method and StatusEvent. StatusEvent is raised when file processing status changes.
We’ll have a Windows Form that displays all this information.


Asynchronous method calling using events and delegates - CodeProject®

No comments: