While Thread not a background thread ( .IsBackground ), the application should stay alive:
static void Main() { Thread thread = new Thread(MoreStuff); thread.IsBackground = false; thread.Start(); Console.WriteLine("Main thread exiting"); } static void MoreStuff() { Console.WriteLine("Second thread starting"); Thread.Sleep(5000);
Nothing more is needed. Note that ThreadPool will use background threads; The problem is that you are using ThreadPool here?
Note: if the second thread is not actually running, there may be a small race where it may exit prematurely; you can block threads starting .
source share