Book Image

Learning .NET High-performance Programming

By : Antonio Esposito
Book Image

Learning .NET High-performance Programming

By: Antonio Esposito

Overview of this book

Table of Contents (16 chapters)
Learning .NET High-performance Programming
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Event-based Asynchronous Pattern (EAP)


The Event-based Asynchronous Pattern (EAP) is a specific design pattern to standardize event-based asynchronous programming features. Such a design is available in multiple classes from .NET itself and is available and suggested in all our implementations if applicable.

Unlike the previously seen APM, in this pattern, any method that supports synchronous execution will add an overloaded method for an asynchronous invocation. The result, instead, will be available only to a specific predefined callback method, one for each available method, within the class itself.

Here is an example showing the WebClient class downloading some web page data:

static void Main(string[] args)
{
    //a simple web client
    var client = new WebClient();

    //register for result callback
    client.DownloadDataCompleted += client_DownloadDataCompleted;

    //invoke asynchronous request
    client.DownloadDataAsync(new Uri("http://www.google.com"));

    Console.WriteLine...