Form closing unexpectedly

C

chris-s

Hi folks,

Grab a brew before you start reading, sorry for the detail!

We are experiencing a problem with our application whereby one form is
appearing to be closed by some other process. Alas, this is one of
those random problems that cannot be repeated.

Form 'A' has a button that brings up form 'B' for some data entry, once
complete it disposes of form 'B' and returns to form 'A'. What we are
seeing is that for some reason form 'B' is being killed off, disposed
or something without any error and the user returning to form 'A'.

Form 'B' is shown using the 'ShowDialog()' method, and is only closed
by one of two buttons that set the 'DialogResult' to either 'OK' or
'Cancel'. There is no call to any 'Close()' or similar method in the
code, so the only way out is by the user pressing one of these buttons.

The 'ShowDialog()' is called as 'this.ShowDialog()' from a method
within the form 'B' object (not static), and the next line of code in
the same method changes some text on form 'A'. Now this is where it
gets really unexpected, these changes to form 'A' are actually getting
made, so it looks like whatever is killing off this form is doing it in
a 'nice' manner and still allowing code to execute in form 'B' rather
than just stopping it in it's tracks.

We have been able to simulate something similar by killing off form 'B'
by going to the 'running processes' in the memory settings, and we
found it closes the form with a dialog result of 'OK'.

Could the OS/CF be closing the form due to low memory? Tho, when we
have done low-memory testing in the past, we have always received some
warning message or other that is not being seen in this case.

Can we detect when an object is being killed off due to low memory?

I find it very odd that stopping the form actually allows it to close
'nicely' and execute further code, how dangerous could that be!

Anybody got some insight into what the OS/CF does when it kills of
stuff?

Chris.
 
G

Guest

Do you get a Closing event for the Form? It's a hack, but if the event
happens use a flag variable that you set on a button click to know if that's
what is closing you.

pseudocode:

bool intentionalclose = false;

void OnOkOrCancelClick()
{
intentionalclose = true;
}

void FormClosingEventHandler()
{
if(!intentionalclose)
CancelClose();
}

-Chris
 
C

chris-s

Thats one of the things we are going to try, but are uncertain what the
effect would be of trying to cancel this action when something else
would seem to be in a critical state to cause it to be closed.
The next couple of days should give us some feedback.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top