How to Restart an Application in C#
Muhammad Maisam Abbas
Feb 16, 2024
This tutorial will discuss the method to restart an application in C#.
Restart an Application With the Application.Restart()
Function in C#
The easiest way to restart an application in C# is to use the Application.Restart()
function. The Application.Restart()
function is used to restart an application in C#. The following code example shows us how we can use the Application.Restart()
function to restart an application in C#.
using System.Windows.Forms;
namespace messagbox {
static class Program {
static void Main() {
Application.EnableVisualStyles();
DialogResult dr = MessageBox.Show("Are you happy now?", "Mood Test", MessageBoxButtons.YesNo);
switch (dr) {
case DialogResult.Yes:
MessageBox.Show("Ok, Bye");
break;
case DialogResult.No:
Application.Restart();
break;
}
}
}
}
Output:
In the above code, we created an application that keeps restarting itself until we select yes from the message box with the Application.Restart()
function in C#.
Author: Muhammad Maisam Abbas
Maisam is a highly skilled and motivated Data Scientist. He has over 4 years of experience with Python programming language. He loves solving complex problems and sharing his results on the internet.
LinkedIn