Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Application.Restart() creates new process for application or no?

Tags:

c#

.net

As I know Application.Restart() restarts an application and creates new Instance of an Application. Does this instance will creates in new process, or old process will be used?

Thanks for an answer.

like image 588
Yuriy Avatar asked Aug 20 '10 12:08

Yuriy


2 Answers

It runs in a new process. The documentation seems a little unclear on whether or not the process is reused but it can be verified by showing the process ID in a text box at start up.

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Application.Restart();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        textBox1.Text = Process.GetCurrentProcess().Id.ToString();
    }
}

You can also see using .NET Reflector that a new process is created:

public static void Restart()
{
    // ...
    ExitInternal();            // Causes the application to exit.
    Process.Start(startInfo);  // Starts a new process.
    // ...
}
like image 163
Mark Byers Avatar answered Sep 17 '22 22:09

Mark Byers


According to the documentation it will start a new instance of the application and thus new process. If there were command line arguments supplied when starting the application those same arguments will be supplied to the new process.

like image 45
Darin Dimitrov Avatar answered Sep 21 '22 22:09

Darin Dimitrov