views:

43

answers:

1

I need to kick off a Sync() process whenever my windows form app is being closed. This sync's data between the local SQL instance and a network SQL instance.

What is the better event to place this in: Closed or Closing?

Are there any factors that might change it from one to the other, as far as being best practice?

As a bonus question: Is there any 'normal' way for the form to close without firing of these two events?

+1  A: 

From FormClosing, you would be able to display the status and progress of the synchronization to the user. For example, when one of my applications is closing it displays "Saving user settings..." in the status bar, calls code to persist customizations, and then allows the close to occur.

Also from FormClosing, you could catch an error from the sync, and cancel the closing of the screen (or prompt the user if they wish to continue closing, etc.).

Thomas G. Mayfield
I am assuming, by your choice of exclusionary words `;)`, that `FormClosed`, by omission, does not offer me these things? Thanks for the answer.
Refracted Paladin
FormClosed occurs after the fact. If you look at FormClosedEventArgs, you only have access to CloseReason. In contrast, FormClosing can be cancelled, and occurs before your form disappears. It's often used for things like "Do you want to save? Yes No Cancel", or "I'm afraid I can't do that, Dave."
Thomas G. Mayfield