Can't close a WinForm app
I have a WinForm application. When I click the X button at the top right cornor of the MainWindow, it could not be closed and there is no exception.
Could anyone explain why?
Thanks!
I have a WinForm application. When I click the X button at the top right cornor of the MainWindow, it could not be closed and there is no exception.
Could anyone explain why?
Thanks!
The only way this can be done is by actually having a EventHandler for FormClosing and then cancelling the event there: Check if something like this exists in your main form code. private Regards,
{
e.Cancel = true;
}
Vikram
This occurs only at some event such as I opened a large document. I doubt I forget to release some resource and caused this problem. Is forgetting release resource will cause such problem?
Thanks!
Can you recreate this scenario in Debug Mode?
Also, if you click on the Close again for a second time does it work?
Regards,
Vikram
In Debug mode, there is no exception thrown. When I click "Break All" command, it stops at the Application.Run(new MainWnd());
I am thinking of a different approach to troubleshoot now.
Add the Event Handler for FormClosing in your Form and register the event.
private void Form1_FormClosing(object sender, FormClosingEventArgs e) See if you get the MessageBox string when it does not close also. Regards,
{
e.Cancel = false;
MessageBox.Show("FormClosing Event");
}
Vikram