Using Is Completed Property C# with Example
using System; using System.Threading; namespace CSharpMultiThreading { public delegate int Addition(int x, int y); class InvokingMethodAsyncronously { static void Main(string[] args) { // Print out the ID of the executing thread. Console.WriteLine("Main() invoked on thread {0}.",Thread.CurrentThread.ManagedThreadId); // Invoke Add() on a secondary thread. Addition b = new Addition(Add); IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null); // This message will keep printing until the Add() method is finished. while(!iftAR.IsCompleted) { Console.WriteLine("Doing more work in Main()!"); Thread.Sleep(1000); } // Obtain the result of the Add() method when ready. int answer = b.EndInvoke(iftAR); Console.WriteLine("10 + 10 is {0}.", answer); } static int Add(int x, int y) { // Print out the ID of the executing thread. Console.WriteLine("Add() invoked on thread {0}.",Thread.CurrentThread.ManagedThreadId); // Pause to simulate a lengthy operation. Thread.Sleep(5000); return x + y; } } }