public static void MyCallback(IAsyncResult result)
        {
            AsyncResult ar    = (AsyncResult)result;
            SumDelegate d     = (SumDelegate)ar.AsyncDelegate;
            int         state = (int)ar.AsyncState;
            int         i     = d.EndInvoke(result);

            Console.WriteLine(i);
            Console.WriteLine(state);
            Console.ReadLine();
        }
Esempio n. 2
0
	public static void Main(){
		SumDelegate sumDelegate1 = new SumDelegate(Sum);
		SumDelegate sumDelegate2 = new SumDelegate(Sum);
		IAsyncResult result1 = sumDelegate1.BeginInvoke(1, 2, null, null);
		IAsyncResult result2 = sumDelegate2.BeginInvoke(3, 4, null, null);
		while(!(result1.IsCompleted && result2.IsCompleted)){
			Thread.Sleep(100);
		}
		int sum1 = sumDelegate1.EndInvoke(result1);
		int sum2 = sumDelegate2.EndInvoke(result2);
		Console.WriteLine("The result of the first async method call is: {0}", sum1);
		Console.WriteLine("The result of the second async method call is: {0}", sum2);
		Console.WriteLine("\nMain thread exiting now...bye!");
	} // end Main() method
  public static void WrapUp(IAsyncResult result){
    SumDelegate sumDelegate = (SumDelegate)result.AsyncState;
	int sum = sumDelegate.EndInvoke(result);
	Console.WriteLine("The result is: {0} ", sum);
  }
Esempio n. 4
0
        static void Main(string[] args)
        {
            Console.WriteLine("запуск приилож");
            int mainThredId = Thread.CurrentThread.ManagedThreadId;

            Console.WriteLine("Поток-- {0}...", mainThredId);

            SumDelegate sumDelegate = new SumDelegate(Sum);

            // sumDelegate.Invoke(2.3, 5.6);
            //IAsyncResult  result= sumDelegate.BeginInvoke(2.3, 5.6, null, null);

            IAsyncResult result = sumDelegate.BeginInvoke(2.3, 5.6,
                                                          new AsyncCallback((incomingResult) =>
                                                                            Console.WriteLine(sumDelegate.EndInvoke(incomingResult))), null);

            Console.WriteLine("Завершение работы");
            Console.ReadLine();
        }