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.
Process process = Process.GetCurrentProcess();
bool isProcessRunning = (Process.GetProcessesByName(process.ProcessName)).Length > 1;
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.
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.
Loop through the processes with the same name and check if the Id is different. If it is, kill it.