Created
March 23, 2017 07:51
-
-
Save Hereigo/93a5b382bd0bba906dda7e6a0e444a01 to your computer and use it in GitHub Desktop.
.Net - Delegate BinaryOp Async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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