title: Is there a better way to keep a console app from returning besides using while?
body: <p>I have a small C# console application that runs some code then checks for a specific executable to complete.</p>
  
  <p>The problem I had (I don't normally write console applications) is when I get to the code that checks for the termination of an executable, my Main() returns and the console application closes. The code which checks for the executable is running thru a Timer(). For the moment I've kept the Main alive by adding while(true) { } and that seems to be working except that it (obviously) eats up a ton of excess CPU time.</p>
  
  <p>Is there a better way to keep the Main() function from returning?</p>
  
  <pre><code>    static Timer tmrCheck = new Timer();
      static void Main(string[] args)
      {
          Initialize();
          while (true) ; // If this line is removed, the application will close after
                         // the last line of Initialize() is run.
      }
  
      static void Initialize()
      {
          tmrCheck.Elapsed += tmrCheck_Elapsed;
          tmrCheck.Interval = 10000;
          tmrCheck.Enabled = true; // After this line, Initialize returns to Main()
      }
  
      static void tmrCheck_Elapsed(object sender, ElapsedEventArgs e)
      {
          // Get a list of processes
          // Check to see if process has exited
          // If so, run *this* code then exit console application.
          // If not, keep timer running.
      }
  </code></pre>