private static void ExitCleanly()
{
if (s_appServerMode)
return; // Continue running even when all apps are shut down
if (s_allowFinalShutdown)
Logger.WriteEvent("Shutting down");
// To be safe - this method might get called recursively (explicitly and from
// Application.Exit() below again). Also could be called when the startup process
// did not complete...we picked an app from the command line, but another process
// was already handling that project.
if (s_cache != null && !s_cache.IsDisposed)
{
DataUpdateMonitor.ClearSemaphore();
using (var progressDlg = new ProgressDialogWithTask(s_threadHelper))
{
progressDlg.Title = string.Format(ResourceHelper.GetResourceString("kstidShutdownCaption"),
s_cache.ProjectId.UiName);
progressDlg.AllowCancel = false;
progressDlg.IsIndeterminate = true;
var stackMgr = s_cache.ServiceLocator.GetInstance<IUndoStackManager>();
if (stackMgr.HasUnsavedChanges)
progressDlg.RunTask(true, CommitAndDisposeCache);
else
{
// For whatever reasons the progress dialog sometimes got closed while
// the worker was still busy which caused a hang.
CommitAndDisposeCache(progressDlg, null);
}
}
}
// This has to be done to zap anything in it weven during a restart triggered by S/R.
SingletonsContainer.Release();
if (s_allowFinalShutdown)
{
Logger.ShutDown();
Application.Exit();
}
}