Posted By

rengber on 11/30/11



Versions (?)

Simplest Possible Background Thread and Console App Lifetime Test

 / Published in: C#


Saw some strange console app behavior while hosting 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();
  6. Console.ReadKey();
  7. }
  9. static void SleepyTime()
  10. {
  11. Thread.Sleep(10000);
  12. }

Report this snippet  

You need to login to post a comment.