title: Terminating duplicate processes with C#
body: <p>So at the beginning of my program I have a piece of code that checks to see if another instance of this process is running. </p>
  
  <pre><code>Process process = Process.GetCurrentProcess();
  bool isProcessRunning = (Process.GetProcessesByName(process.ProcessName)).Length &gt; 1;
  </code></pre>
  
  <p>If the the process is running then I open a message box that says the process is already running and asks the user if they want to terminate the current process and open a new one.</p>
  
  <p>If the dialog result is yes then I use process.kill to close the process. The problem is I will have two of these processes running, so how do I specify which one to close? The process name will be exactly the same, and I want to close the one that was opened first.</p>