Webapache
Webapache

Reputation: 97

Wait until "Write complete"

"simple" question to the "streamer guy's there". My program starts SQL backup processes in single tasks, for any backup per DB. All the tasks start one by one after the first task finished. But, when the SQL backup command goes to the SQL server, than the process to write the backupfile takes more time then task takes to finish. At this moment, the user can close the program and skip the backupprocess to the big DB files. Is there a way to block my programm from closing, until every single backupfile is completly written to the HDD?

Upvotes: 0

Views: 271

Answers (1)

Domysee
Domysee

Reputation: 12846

You can handle the Closing of the Window like this:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (BackupStillRunning)
        e.Cancel = true;
    else
        e.Cancel = false;
}

What you should do though is ask the user if he really wants to quit, something like this:

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (BackupStillRunning)
    {
        if (MessageBox.Show("The backup is still running, if you close the application, the backup will be cancelled. Do you want to proceed?", "Caption", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            e.Cancel = true;
    }
    else
    {
        e.Cancel = false;
    }
}

Simply not letting the user close the application will quickly get frustrating. If you really dont want the user to close the application, you should at least show a message explaining why.

As Damien_The_Unbeliever pointed out, there is no way to completely prevent the application from shutting down.

Upvotes: 1

Related Questions