title: Process often exiting prematurely
body: <p>I have this small piece of code (easy to try):</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          List&lt;string&gt; paths = new List&lt;string&gt;() { "1.docx", "2.docx", "3.docx", "4.docx" };
  
          foreach (string path in paths)
          {
              string path2 = @"Path\to\those\files" + path;
  
              Process process = new Process();
              process.StartInfo = new ProcessStartInfo(path2);
              System.Diagnostics.Debug.WriteLine("~&gt;" + path2);
              process.Exited += (s1, e1) =&gt; process_Exited(path2);
              process.EnableRaisingEvents = true;
              process.Start();
          }
  
          while (true) { }
      }
  
      static void process_Exited(string path)
      {//&lt;~ breakpoint here
  
      }
  }
  </code></pre>
  
  <p>What is happening is sometimes, the breakpoint is hit moments after I start the application despite it having to wait for the processes to be exited one after another. It is always the <strong>last</strong> file of all, be it 2 files, 3 files, 4 files or more. The only time the breakpoint is never hit prematurely is when <code>paths</code> contains only one file. (By the way, maybe I could not care much about this strange behaviour, but when I really exit the .docx file (the last one from the paths list), the breakpoint is not hit.</p>
  
  <p><strong>Why is this (process sometimes exiting prematurely) happening and how to prevent that?</strong></p>
  
  <p><strong>UPDATE:</strong> I just noticed it is not necessarily the last of files in <code>paths</code>, sometimes it is random one.</p>