Restart an Application in C#

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:

C# Restart Application C# Restart Application

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#.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.