views:

80

answers:

3

Hi,

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.

+4  A: 

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.

Darin Dimitrov
+1 from here - a link to documentation is always good. However the documentation seems unclear on this point. Can you point to the specific part where it says that the process will not be reused?
Mark Byers
+8  A: 

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.
    // ...
}
Mark Byers
Yes, It's a really good answer.
Yuriy
A: 

It starts a new instance. You could run into issue where if your original application still have worker thread running, the original process may not be killed soon enough that you will end up having 2 instances running at the same time (which will be shown in task manager).

dsum