4

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?

4
  • why dont u try process.start? Commented Jul 4, 2012 at 16:32
  • 3
    are you trying to create a new instance of a Program or of a Form? Commented Jul 4, 2012 at 16:32
  • 1
    actually it is the other way around - newly created form1 becomes the owner of the current form. It does not happen, however, since the new instance is not made visible. Commented Jul 4, 2012 at 16:33
  • then start a new process as per Desolator's answer... Commented Jul 4, 2012 at 16:38

3 Answers 3

5

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();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

5

You can use instead new Form1().Show();, but when your current instances exists, the other one will exit too. So, to be fully independent, it is better to use System.Diagnostics.Process.Start(string path) which starts your program exactly as if one double clicks it.

Comments

0
(new Form1()).Show();

(new Form1()).Show();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.