Best practise of closing a form and backing up sql server data

-GSS-

Member
Joined
Jun 23, 2007
Messages
11
Programming Experience
Beginner
I've read of different ways to close a form. I was wondering, in terms of performance, which is the best code implementation? I've read that some methods of closing a form won't save or let a process finish. Which is the best method?

The other question I've alwas wondered is how can I provide a feature in an application, such as the the db-driven application I have made with DevExpress XtraGrids on the front-end, to backup the data stored (in a backend sql server db)?

Thanks
 
If a form was displayed by calling its Show method then calling its Close method will dismiss it and destroy it.

If a form was displayed by calling its ShowDialog method then you should dismiss it by setting its DialogResult property. Calling its Close method is equivalent to setting its DialogResult property to Cancel but that should be avoided. If you want ShowDialog to return Cancel then you should explicitly set the form's DialogResult property to Cancel. Once dismissed a dialogue is not destroyed until you call its Dispose method.

If you call Application.Exit then that will close all forms implicitly.

The only reason that I can think of for this statement to be true:
I've read that some methods of closing a form won't save
would be if you had your code to save the data in the Closing or Closed event handler of the form and then called Application.Exit. This was a problem in .NET 1.x because those events would not be raised. It's not a problem in .NET 2.0 though because you should use the FormClosing and FormClosed events, which are raised when you call Application.Exit.

This:
I've read that some methods of closing a form won't ... let a process finish.
sounds like complete twaddle. The only thing that I can think of that could be construed that way is if you add code to prevent the form closing in the Closing event handler. Again, this is not an issue in .NET 2.0 because the FormClosing event tells you why the form is closing. You can then make sure that you let the form close when it should and only prevent it when it's appropriate. An example might be if you wanted to minimise to the system tray instead of closing if the user pressed the Close button in the title bar, but you'd still let the form close when Windows was shutting down.
 
Back
Top