Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create another instance of a .NET program within one instance by code?

I need to be able to create another brand new instance of a program on a button click while keeping the existing instance.

this.ShowDialog(new Form1());

The above statement causes the current form to be the owner of the new form and I need the second instance to be independent of the existing instance.

Can anyone help me with this?

like image 940
n00b Avatar asked Dec 26 '22 22:12

n00b


1 Answers

To expound on Desolator's answer here is a simplistic example you can try a Form and a Button:

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

    private void button1_Click(object sender, EventArgs e)
    {
        Process p = new Process();
        p.StartInfo.FileName = Application.ExecutablePath;
        p.Start();
    }
}
like image 129
Mark Hall Avatar answered May 01 '23 10:05

Mark Hall