Merge pull request #823 from DavidKarlas/master
[mono.git] / mono / tests / bug-438454.cs
1 using System;
2 using System.Threading;
3
4 class Program
5 {
6     static void Main ()
7     {
8         var d = AppDomain.CreateDomain("Foo");
9         d.ProcessExit += AppDomain_ProcessExit;
10
11         AppDomain.CurrentDomain.ProcessExit += new EventHandler (AppDomain_ProcessExit);
12         ThreadPool.QueueUserWorkItem (new WaitCallback (Proc));
13         Thread.Sleep (1000);
14     }
15
16     static void Proc (object unused)
17     {
18         Thread.CurrentThread.IsBackground = false;
19         Thread.Sleep (5000);
20         Console.WriteLine ("done");
21     }
22
23     static void AppDomain_ProcessExit (object sender, EventArgs e)
24     {
25         Console.WriteLine ("exit");
26
27         // No messages should be printed, as when this event is fired the
28         // ThreadPool has been shutdown, thus `a.BeginInvoke()` has no effect.
29         Action a = () => {
30             int i = 0;
31                         while (i < 1024)
32                 Console.WriteLine ("Ha! {0}", i++);
33         };
34         a.BeginInvoke (null, null);
35     }
36 }