Skip to content

Instantly share code, notes, and snippets.

@Hereigo
Created March 23, 2017 07:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hereigo/93a5b382bd0bba906dda7e6a0e444a01 to your computer and use it in GitHub Desktop.
Save Hereigo/93a5b382bd0bba906dda7e6a0e444a01 to your computer and use it in GitHub Desktop.
.Net - Delegate BinaryOp Async
public delegate int BinOp(int a, int b);
public static class Del_BinOp_Async
{
private static int DelegThreadMeth(int intData, int timeToSleep)
{
Console.WriteLine("DelegateThread Started.");
System.Threading.Thread.Sleep(timeToSleep);
Console.WriteLine("DelegateThread Finished.");
return ++intData;
}
private static void MyIAsyncRezult(IAsyncResult iar)
{
if (iar == null)
throw new ArgumentNullException("iar null!");
BinOp boDel = iar.AsyncState as BinOp;
System.Diagnostics.Trace.Assert(boDel != null, "Wrong object type!");
var x = boDel.EndInvoke(iar);
Console.WriteLine("Rezult : " + x);
}
public static void Test()
{
BinOp boDel = DelegThreadMeth;
IAsyncResult iar = boDel.BeginInvoke(1, 3000, MyIAsyncRezult, boDel);
while (true)
{
Console.Write(".");
System.Threading.Thread.Sleep(50);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment