Home > Net >  I form out why you need to click on twice to exit? To solve?
I form out why you need to click on twice to exit? To solve?

Time:10-06

Private void Form1_FormClosing (object sender, FormClosingEventArgs e)
{
If (DialogResult. Yes==MessageBox. Show (" are you sure you want to leave your system?" , "tip", MessageBoxButtons YesNo, MessageBoxIcon. Information))
{
Application. The Exit ();
WriteRecord (" shutdown records: "+ DateTime. Now. The ToString ());
}
The else
{
E.c. with our fabrication: ancel=true;
}
}
Received the code. Basic written as! Can I withdraw from the need to click twice!

CodePudding user response:

Don't understand, but see the two sequential write backwards;
Application. The Exit ();
WriteRecord (" shutdown records: "+ DateTime. Now. The ToString ());

CodePudding user response:

If (MessageBox. Show (" are you sure you want to leave your system?" , "tip", MessageBoxButtons YesNo, MessageBoxIcon. Information)) ok?

CodePudding user response:

You click on the x, trigger the closing event for the first time, pop-up box after the execution Applacation. The exit (), the main process began to cancellation of the workplace, including close already open form1, trigger the closing event again

CodePudding user response:

Use Form1_FormClosed, estimates that can be closed at a time

CodePudding user response:

Application. The Exit ();
Can be changed to
Environment. The Exit (0);

CodePudding user response:

Environment. The Exit (0); This is good

CodePudding user response:

//Application. The Exit (); Direct this line comments don't can!

Application. Exit (will also go to call a closed event, he will be prompted twice is closed, the first point is the second point you ever he would still be closed,

CodePudding user response:

Form1_FormClosing itself is closed for events, you don't want to other operating himself was shut down,
Unless you are a program process refund not only thoroughly consider using these
  •  Tags:  
  • C#
  • Related