Welcome to mirror list, hosted at ThFree Co, Russian Federation.

delegate.cs « exiting « tests « mono - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bf4adfd981fadf2cb83240451a8d9d3bf7a7af16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Threading;
using System.Runtime.InteropServices;

class foo {
	delegate void foo_delegate ();
	
	static void function () {
		Console.WriteLine ("Delegate method");
	}

	static void async_callback (IAsyncResult ar)
	{
		Console.WriteLine ("Async callback " + ar.AsyncState);
	}
	
	public static void Main () {
		foo_delegate d = new foo_delegate (function);
		AsyncCallback ac = new AsyncCallback (async_callback);
		IAsyncResult ar1 = d.BeginInvoke (ac, "foo");

		Console.WriteLine("Waiting");
		ar1.AsyncWaitHandle.WaitOne();
		Console.WriteLine("Sleeping");
		Thread.Sleep(1000);
		Console.WriteLine("EndInvoke");
		d.EndInvoke(ar1);
		Console.WriteLine("Sleeping");

		Thread.Sleep(1000);
		Console.WriteLine("Main returns");
	}
}