We have an application running at a client that is displaying strange behavior. At random times during the day the OK button (which calls the Form.Close method) on certain forms will not cause the Form to close. With that I mean that the user will click the button, in the trace it will display that Form.Close was called but the form will not close.
The strange thing is that the Form itself is still responsive so they can click any button on the form and the code behind the buttons will execute but the form just will not close.
This state lasts for anything between a couple of seconds to a couple of minutes. Then all of a sudden the form will start disposing and disappear. Really strange.
So to recap, the following happens:
Form.ShowDialog()
-> The form displaysForm.Close()
is called -> The user clicked the close buttonForm.ShowDialog
Things to note:
explorer.exe
process has stopped on the PC, can this have an impact on a form's behavior? We are scheduling a rebuild of the PC.My question is if anyone is aware of a scenario that can cause the described behavior above?
I'm not an expert at Forms but as I understand it, when you call Form.Close
, the form doesn't close instantly, the current method that called Close first finishes and then another process triggers the form to start closing and dispose.
Can this be related to the explorer.exe
process not running?
Any insight would be greatly appreciated.
*** Edit
Also note that we can't replicate the issue, it happens randomly at the client.
Reminds me of C# Why does form.Close() not close the form?
Do you have any code in the button click event handler just after the this.Close() line?
What I mean:
private void OKButton_Click(object sender, EventArgs e)
{
this.Close();
somecodehere <-- is there any code here? (after this.Close)
}
Because Form.Close doesn't close the Form immediately, so if you have code after the call it will still execute, and maybe that's what prevents the form from closing.
May be you can hide
the form first before you close so that user would not get restless and try to close it
Form.Hide();
Form.Close();
Another reason is on window close or destructor may be you are trying to save a bigger file or some activity. If so try to do that in thread. So that it would close the form soon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With