19.4. Invoking a Method Asynchronously

To instruct the BinaryOp delegate to invoke Add() asynchronously, you will modify the logic in the previous project (feel free to add code to the existing project, however in your lab downloads, you will find a new Console Application named AsyncDelegate). Update the previous Main() method as follows:

static void Main(string[] args) { Console.WriteLine("***** Async Delegate Invocation *****"); // Print out the ID of the executing thread. Console.WriteLine("Main() invoked on thread {0}.", Thread.CurrentThread.ManagedThreadId); // Invoke Add() on a secondary thread. BinaryOp b = new BinaryOp(Add); IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null); // Do other work on primary thread... Console.WriteLine("Doing ...

Get Pro C# 2010 and the .NET 4 Platform, Fifth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.