C# Tips

C# Tip Article

How to restart program in C#

How do you restart the current process in C#?

Well basically it is to start the same program instance as current process and close the current process at the same time. Depending on application types (such as WinForms, Console application), the implementation might be a little different, but the basic idea is same.

Here is an example of how to.

private void RestartProgram()
{
	// Get file path of current process 
	var filePath = Assembly.GetExecutingAssembly().Location;
	//var filePath = Application.ExecutablePath;  // for WinForms

	// Start program
	Process.Start(filePath);
	
	// For Windows Forms app
	Application.Exit();
				
	// For all Windows application but typically for Console app.
	//Environment.Exit(0);
}

There is another simpler way for WinForms application. That is, you can simply call Application.Restart(). But this method is not reliable in some cases.