Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Last active December 12, 2015 05:38
Show Gist options
  • Save jonpryor/4722994 to your computer and use it in GitHub Desktop.
Save jonpryor/4722994 to your computer and use it in GitHub Desktop.
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