internal static void ShutdownApp(FwApp app, bool fSaveSettings)
{
if (app != s_teApp && app != s_flexApp)
throw new ArgumentException("Application must belong to this FieldWorks", "app");
if (fSaveSettings)
app.SaveSettings();
if (s_activeMainWnd != null && app.MainWindows.Contains(s_activeMainWnd))
{
// The application that owns the active main window is being disposed. This
// means that the window is, most likely, already disposed.
s_activeMainWnd = null;
}
RecordLastAppForProject();
if (app == s_teApp)
s_teApp = null;
else if (app == s_flexApp)
s_flexApp = null;
// Make sure we do this after we set the variables to null to keep a race condition
// from happening where we want to GetOrCreateApplication() for the app that is
// being disposed.
try
{
app.Dispose();
}
catch
{
// continue shutdown even with an exception. It's possible we're shutting down because
// of a crash and we don't know what state the application is in.
}
ExitIfNoAppsRunning();
}