Posted By

rengber on 11/30/11


Tagged

Multithreading


Versions (?)

Simplest Possible Background Thread and Console App Lifetime Test


 / Published in: C#
 

URL: http://www.albahari.com/threading/

Saw some strange console app behavior while hosting quartz.net had to doublecheck that a console app will not exit while background threads are running. In the example below, once the main method ends, the app stays alive for 10 seconds while the background thread finishes.

  1. static void Main(string[] args)
  2. {
  3. Thread t = new Thread(SleepyTime);
  4. t.Start();
  5.  
  6. Console.ReadKey();
  7. }
  8.  
  9. static void SleepyTime()
  10. {
  11. Thread.Sleep(10000);
  12. }

Report this snippet  

You need to login to post a comment.