title: System.Diagnostics.Process.HasExited always returns true and Process.Exited event handler always hits when process is still open
body: <p>I am currently having issues with a piece of my code. This code works perfectly fine (even without some of the extra if statements) on my machine when I run it both through Visual Studio 2013 and when I publish using ClickOnce. On the client's machine, the event handler for the process exiting catches, the process ID is correct, and the process.hasExited returns true all while the process is still open. The process opens a pdf for them to sign and waits for them to save it and close it before proceeding. It uses Adobe Acrobat Reader DC.</p>
  
  <p>The error message received is from the catch block of the event handler method:</p>
  
  <p>System.IO.IOException: The process cannot access the file because it is being used by another process. </p>
  
  <p>This occurs at the call for getReaders_NewHire(emp).</p>
  
  <p>This is the method that opens the process:</p>
  
  <pre><code>private void pdfAndEmail(Employee employee, Requirements requirements)
      {
          try
          {
              PDFUtility pdfu = new PDFUtility();
              pdfu.createPDFMG_NewHire(employee, requirements);
  
              emp = employee;
  
              process = new System.Diagnostics.Process();
              string path = System.IO.Path.GetTempPath() + "\\ITResources\\Manager\\NewHire_" + employee.m_name.Replace(" ", "") + ".pdf";
              Uri pdf = new Uri(path, UriKind.RelativeOrAbsolute);
              process.StartInfo.FileName = pdf.LocalPath;
              process.EnableRaisingEvents = true;
              process.Exited += new EventHandler(process_Exited);
              process.Start();
              pid = process.Id;
          }
  
          catch (Exception e)
          {
              MessageBox.Show(e.ToString(), "Error Message", MessageBoxButton.OK, MessageBoxImage.Error);
          }
      }
  </code></pre>
  
  <p>and this is the event handling method:</p>
  
  <pre><code>private void process_Exited(object sender, EventArgs e)
      {
          try
          {
              if (process.Id == pid)
              {
                  if (process.HasExited)
                  {
                      PDFUtility pdfu = new PDFUtility();
                      pdfu.getReaders_NewHire(emp);
  
                      Emailer send = new Emailer();
                      send.SendAfterMG_NewHire();
                  }
                  else
                      MessageBox.Show("Process has not exited.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
              }
          }
  
          catch (Exception ex)
          {
              MessageBox.Show(ex.ToString(), "Error Message", MessageBoxButton.OK, MessageBoxImage.Error);
          }
      }
  </code></pre>
  
  <p>The getReaders method in the event handler needs to read the file that the client has to sign so it must be closed beforehand. I cannot force a close because I will never know how long it will take them to sign and I can't have the email being sent out before they've signed and saved the pdf. </p>
  
  <p>I've already tried using the WaitForExit() method and it skips completely (only on my client's computer). I am running Windows 10, but the client is running Windows 7. I have not been able to find any documentation about these methods not working on Win7. </p>
  
  <p>Note: I understand that the if statements in the event handler method are a bit redundant, but I was desperate to find where it was catching. </p>
  
  <p>Any help would be greatly appreciated.</p>
  
  <p>FIXED: I ended up have a Message Box pop up after my PDF was signed to assist the WaitForExit() in the Background Worker thread. After this message box's OK button is pressed (because they pause the application and wait for a response), it then reads the pdf files.</p>