Hi,
I have an application that when the user close the window, I'd like to do some time consuming task (update database). At the same time, I want to show busy indicator. When the task is done, close the window as per normal. Here's the sample code
but it's not working. The "e.Cancel = false" doesn't close the window. Can anyone help? Where did I do wrong?
Thanks!
I have an application that when the user close the window, I'd like to do some time consuming task (update database). At the same time, I want to show busy indicator. When the task is done, close the window as per normal. Here's the sample code
public
partial
class
MainWindow
{
public
MainWindow()
{
InitializeComponent();
Closing += MainWindowClosing;
}
void
MainWindowClosing(
object
sender, CancelEventArgs e)
{
e.Cancel =
true
;
busyIndicator.IsBusy =
true
;
var worker =
new
BackgroundWorker()
;
worker.DoWork += (s, args) => Thread.Sleep(TimeSpan.FromSeconds(3));//just for testing
worker.RunWorkerCompleted += (s, args) =>
{
busyIndicator.IsBusy =
false
;
e.Cancel =
false
;
};
worker.RunWorkerAsync();
}
}
but it's not working. The "e.Cancel = false" doesn't close the window. Can anyone help? Where did I do wrong?
Thanks!