Last active
December 12, 2015 05:38
-
-
Save jonpryor/4722994 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Threading; | |
class Test { | |
const int NumBusyWaiters = 10; | |
public static void Main () | |
{ | |
AppDomain.CurrentDomain.ProcessExit += (s, e) => { | |
Console.WriteLine ("Blocking process exit!"); | |
while (true) { | |
Console.WriteLine ("Blocking process exit!"); | |
} | |
}; | |
var waiters = Enumerable.Range (0, NumBusyWaiters).Select (n => { | |
var t = new Thread (BusyLoop); | |
t.Start (); | |
return t; | |
}).ToArray (); | |
Console.WriteLine ("Exiting..."); | |
Environment.Exit (0); | |
} | |
static void BusyLoop () | |
{ | |
while (true) { | |
Console.WriteLine ("Working from thread {0}", Thread.CurrentThread.ManagedThreadId); | |
Thread.Sleep (1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment