Example for Asynchonous Delegates

Manimaddu
Posted by Manimaddu under C# category on | Points: 40 | Views : 448
Hi all...

The below code is example for Asynchonous Delegate

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace AsynchonousDelegateDemo
{
public class DelegateDemo4
{
delegate Guid DoComplexLogic();
public static void Main(string[] args)
{
DoComplexLogic docomplexLogic = MyComplexLogic;
docomplexLogic.BeginInvoke(new AsyncCallback(CallBackMyComplexTask), docomplexLogic);
Console.WriteLine("New task is started!");
Console.Read();
}
public static void CallBackMyComplexTask(IAsyncResult asyncResult)
{
DoComplexLogic doComplexLogic = (DoComplexLogic)asyncResult.AsyncState;
Guid newGuid = doComplexLogic.EndInvoke(asyncResult);
Console.WriteLine(newGuid);
}
public static Guid MyComplexLogic()
{
Thread.Sleep(3000);
Console.WriteLine("BigTask Completed...");
return Guid.NewGuid();
}
}
}



Thank you..

Comments or Responses

Login to post response