diff --git a/SafeExamBrowser.Applications/ExternalApplication.cs b/SafeExamBrowser.Applications/ExternalApplication.cs index 5b500e2a..a54a43a2 100644 --- a/SafeExamBrowser.Applications/ExternalApplication.cs +++ b/SafeExamBrowser.Applications/ExternalApplication.cs @@ -81,6 +81,7 @@ namespace SafeExamBrowser.Applications { logger.Info("Starting application..."); InitializeInstance(processFactory.StartNew(executablePath)); + logger.Info("Successfully started application."); } catch (Exception e) { @@ -92,18 +93,28 @@ namespace SafeExamBrowser.Applications { applicationMonitor.InstanceStarted -= ApplicationMonitor_InstanceStarted; - lock (@lock) + try { - if (instances.Any() && !settings.AllowRunning) + lock (@lock) { - logger.Info("Terminating application..."); - - foreach (var instance in instances) + if (instances.Any() && !settings.AllowRunning) { - instance.Terminate(); + logger.Info($"Terminating application with {instances.Count} instance(s)..."); + + foreach (var instance in instances) + { + instance.Terminated -= Instance_Terminated; + instance.Terminate(); + } + + logger.Info("Successfully terminated application."); } } } + catch (Exception e) + { + logger.Error($"Failed to terminate application!", e); + } } private void ApplicationMonitor_InstanceStarted(Guid applicationId, IProcess process) diff --git a/SafeExamBrowser.Applications/ExternalApplicationInstance.cs b/SafeExamBrowser.Applications/ExternalApplicationInstance.cs index 0ca0ea46..fbf1c567 100644 --- a/SafeExamBrowser.Applications/ExternalApplicationInstance.cs +++ b/SafeExamBrowser.Applications/ExternalApplicationInstance.cs @@ -66,7 +66,11 @@ namespace SafeExamBrowser.Applications var terminated = process.HasTerminated; - if (!terminated) + if (terminated) + { + logger.Info("Application instance is already terminated."); + } + else { FinalizeEvents();