Tuesday, December 24, 2013

how to cretae Delegate in C#

using System;
using System.Threading;

public delegate int mydelegate(int a);

class Program
{
static void Main(string[] args)
{
mydelegate myptr = sq;
IAsyncResult res=myptr.BeginInvoke(10, null, null);
Console.WriteLine("Back TO Main Thread");
while (res.IsCompleted==false)
{

Console.WriteLine("Procesing...");
Thread.Sleep(1000);
}
Console.WriteLine("yar kya karu");
int result = myptr.EndInvoke(res);
}

static int sq(int b)
{
Console.WriteLine("Processing started");
Thread.Sleep(2000);
return b * b;
}
}

No comments:

Post a Comment