public void CloseApp(bool forceClose = false)
{
BackgroundWorker queueWorker = new BackgroundWorker();
queueWorker.DoWork += (s, e) => {
while (IsBusy && !forceClose) {
System.Threading.Thread.Sleep(100);
}
};
queueWorker.RunWorkerCompleted += (s, e) => {
if (Application.Current == null) {
System.Diagnostics.Process.GetCurrentProcess().Kill();
return;
}
if (!Application.Current.Dispatcher.CheckAccess()) {
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate () {
Application.Current.Shutdown();
}));
} else {
Application.Current.Shutdown();
}
};
queueWorker.RunWorkerAsync();
}