How to create another instance of a .NET program in one instance using code?

I need to create another new instance of the program when I click a button while saving an existing instance.

this.ShowDialog(new Form1()); 

The above statement makes the current form own the new form, and I need the second instance to be independent of the existing instance.

Can anyone help me with this?

+4
source share
3 answers

To explain the answer to Desolator, here is a simplified example where you can try the form and 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(); } } 
+5
source

Instead, you can use new Form1().Show(); but when your current instances exist, another one will come out too. Thus, to be completely independent, it is better to use System.Diagnostics.Process.Start(string path) , which launches your program exactly as if it had double-clicked on it.

+5
source
 (new Form1()).Show(); (new Form1()).Show(); 
0
source

All Articles