Click here to Skip to main content
15,913,610 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want restart main program project exe, i'm use this code but not work.
C#
form1.close();
form1.show();
Posted

 
Share this answer
 
v3
Comments
CPallini 29-Dec-14 2:50am    
5.
ridoy 29-Dec-14 2:52am    
Thank you, :)
Sergey Alexandrovich Kryukov 29-Dec-14 3:33am    
Right, a 5.
—SA
ridoy 29-Dec-14 3:34am    
Thank you, Sergey.
An important question ask here is: Why do you want to restart the Application when it is your own code that closes (evidently) the Main Form which (in a WinForm app) terminates the Application ?

Why close the Application/Form if you want to keep it "alive" ?

Why not do something like write an EventHandler for the Main Form 'Closing Event: and give the user the choice to quit the Application, or keep going ?
C#
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    if (
        MessageBox.Show(
        "Quit the Application ?",
        "Do you really want to quit ?",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Warning,
        MessageBoxDefaultButton.Button2)
        == DialogResult.No)
    {

        e.Cancel = true;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900