You can create another application that you will start when you exit the application, and which in turn will launch your application again. It looks like the patcher will work, only without fixing anything. On the plus side, you can have a loop in this "restart-application" that checks all running processes for your main application process and only tries to restart it when it no longer appears in the process - and you got bare bones for the patcher too :) Although you have no problem restarting the application due to the fact that it is still in the process list, this is what I will do when I do this in a production environment, since it gives you the most control IMHO.
Edit:
This part of the button event handler (or where you want to restart the application) of your main application ( Process2BRestarted.exe in my case):
private void cmdRestart_Click(object sender, EventArgs e) { var info = new ProcessStartInfo(); info.FileName = "ProcessReStarter"; info.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(info); Application.Exit(); }
This should go into your / restarter utility application ( ProcessReStarter.exe ):
private void MainForm_Load(object sender, EventArgs e) {
By clicking the restart button, you will create a new process, ProcessReStarter.exe , which will iterate over the list of processes of all running processes, checking that Process2BRestarted is still running. If the process no longer appears in the list, it will start the new Process2BRestarted.exe process and exit itself.
source share