SEBWIN-361: Fixed concurrency issue when terminating external applications and ensured termination operation continues even with failure.

This commit is contained in:
dbuechel 2020-02-26 08:49:16 +01:00
parent 07bb78e637
commit 2b7ff4561a
2 changed files with 22 additions and 7 deletions

View file

@ -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)

View file

@ -66,7 +66,11 @@ namespace SafeExamBrowser.Applications
var terminated = process.HasTerminated;
if (!terminated)
if (terminated)
{
logger.Info("Application instance is already terminated.");
}
else
{
FinalizeEvents();