There are many ways to achieve this, but one could looke like this:
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
Form dlg=null;
ThreadPool.QueueUserWorkItem(state => {
dlg = new ShuttingDownUI();
dlg.ShowDialog();
});
// do hard work with saving and stuff
if (dlg != null)
{
dlg.BeginInvoke((Action) dlg.Close);
}
}
In the OnClosing method of your form, open a "shutting down dialog" on a separate thread containing a ProgressBar
with its Style
property set to Marquee
. Then go on and do your saving/closing down procedure, and when you are done, close the "shutting down" dialog.
The important thing is that the form with the marquee must be on a separate thread than the one where the work is being done. Otherwise it will not animate, and the app will still appear as if it is not responding.