Question

I have a large c# project at work that controls a radar jammer. When the project is loaded, we create 3 threads and each one opens what we call a "mainform" (closing one of the mainforms will shut down the program.

The problem I'm currently encountering is that I am able to close one of the mainforms before making sure all other forms have been saved and properly closed themselves. What is the best way to go about this task? My current recommendation is to keep a global stack that keeps track of all open forms and before closing the mainform, it'll attempt to save and close all the forms in the stack.

Was it helpful?

Solution

If your functionality is to have the forms no longer displayed but still have access to the form's data internally, you can use hide() instead of closing them right away.

However, you should probably have a list like you said that contains references to all mainforms and iterates through them to save their information before truly getting rid of them.

EDIT: You can always make use of the OnFormClosing method as well. That is the more event driven approach. http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top