c#非同期Func

4572 ワード

public class TestFunc { private string Uname = "joyet"; private int Num1 = 109; private int Num2 = 5; private int Num3 = 0; /// /// /// public void TestYncMethod() { Console.WriteLine(" Add ====="); Func<int,int,int> func = TestMethods.Add; func.Invoke(Num1, Num2); Console.WriteLine(" Add =====。"); } /// /// /// public void TestAsyncPlus() { Console.WriteLine(" Add ====="); Func<int,int,int> func = TestMethods.Add; IAsyncResult result = func.BeginInvoke(Num1, Num2, new AsyncCallback(TestAsyncPlusCallBack), null); Console.WriteLine(" Add =====。"); } /// /// , , , 。 /// /// private void TestAsyncPlusCallBack(IAsyncResult result) { Func<int, int, int> f = (Func<int, int, int>)((AsyncResult)result).AsyncDelegate; Num3 = f.EndInvoke(result); Console.WriteLine(" Add :" + Convert.ToString(Num3)); } }
 
転載先:https://www.cnblogs.com/joyet-john/p/7505134.html