0

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.

  • Do not allow the user to close the mainforms during this intialization process. You handle the event that handles how your program Closes. – Security Hound Jun 22 '12 at 14:40
  • Yes, otherwise the program would be too slow to load. –  Jun 22 '12 at 15:11

1 Answers1

0

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

BlackVegetable
  • 12,594
  • 8
  • 50
  • 82
  • The end goal is to close the program but before doing so we want to make sure that all other forms (not just the mainforms) are saved so it's not really hiding that we want. So yeah the list seems like the best option here unless there's a way to throw events or something of the sort? –  Jun 22 '12 at 15:14