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!

[194 byte] By [LeiJiang] at [2007-12-16]
# 1
Hi,

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 void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel =
true;
}

Regards,
Vikram

Vikram at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
No, there is no such code.

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!

LeiJiang at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 3
Hi,

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

Vikram at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 4
It appears both in Release and Debug mode, and it will not close dispite how many times I click the close button.

In Debug mode, there is no exception thrown. When I click "Break All" command, it stops at the Application.Run(new MainWnd());

LeiJiang at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 5
Hi,

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)
{
e.Cancel = false
;
MessageBox.Show("FormClosing Event");
}

See if you get the MessageBox string when it does not close also.

Regards,
Vikram

Vikram at 2007-9-9 > top of Msdn Tech,Windows Forms,Windows Forms General...