sample code for the EndInvoke method
-
-
-
- using System;
- using System.Threading;
-
- public delegate int DelegateClass(out DateTime start,out DateTime stop);
-
- public class Starter {
-
- public static void Main() {
- DelegateClass del = MethodA;
- DateTime start;
- DateTime stop;
- IAsyncResult ar = del.BeginInvoke(out start, out stop,null, null);
- ar.AsyncWaitHandle.WaitOne();
-
- int elapse = del.EndInvoke(out start, out stop, ar);
- Console.WriteLine("Start time: {0}", start.ToLongTimeString());
- Console.WriteLine("Stop time: {0}", stop.ToLongTimeString());
- Console.WriteLine("Elapse time: {0} seconds",elapse);
- }
- public static int MethodA(out DateTime start, out DateTime stop) {
- start = DateTime.Now;
- Thread.Sleep(5000);
-
- stop = DateTime.Now;
- return (stop - start).Seconds;
- }
- }
-
-
-
-
-
-
using System;
using System.Threading;
public delegate int DelegateClass(out DateTime start,out DateTime stop);
public class Starter {
public static void Main() {
DelegateClass del = MethodA;
DateTime start;
DateTime stop;
IAsyncResult ar = del.BeginInvoke(out start, out stop,null, null);
ar.AsyncWaitHandle.WaitOne();
int elapse = del.EndInvoke(out start, out stop, ar);
Console.WriteLine("Start time: {0}", start.ToLongTimeString());
Console.WriteLine("Stop time: {0}", stop.ToLongTimeString());
Console.WriteLine("Elapse time: {0} seconds",elapse);
}
public static int MethodA(out DateTime start, out DateTime stop) {
start = DateTime.Now;
Thread.Sleep(5000);
stop = DateTime.Now;
return (stop - start).Seconds;
}
}
|
HTML code for linking to this page:
Related in same category :
-
|