SEBWIN-312: Ensured already known application instances are not initialized twice.

This commit is contained in:
dbuechel 2019-12-02 17:00:55 +01:00
parent f1fc27e451
commit d8a27e9298

View file

@ -108,12 +108,17 @@ namespace SafeExamBrowser.Applications
private void ApplicationMonitor_InstanceStarted(Guid applicationId, IProcess process) private void ApplicationMonitor_InstanceStarted(Guid applicationId, IProcess process)
{ {
if (applicationId == Id) lock (@lock)
{
var isNewInstance = instances.All(i => i.Id != process.Id);
if (applicationId == Id && isNewInstance)
{ {
logger.Info("New application instance was started."); logger.Info("New application instance was started.");
InitializeInstance(process); InitializeInstance(process);
} }
} }
}
private void Instance_Terminated(int id) private void Instance_Terminated(int id)
{ {
@ -126,6 +131,8 @@ namespace SafeExamBrowser.Applications
} }
private void InitializeInstance(IProcess process) private void InitializeInstance(IProcess process)
{
lock (@lock)
{ {
var instanceLogger = logger.CloneFor($"{Name} ({process.Id})"); var instanceLogger = logger.CloneFor($"{Name} ({process.Id})");
var instance = new ExternalApplicationInstance(Icon, instanceLogger, nativeMethods, process); var instance = new ExternalApplicationInstance(Icon, instanceLogger, nativeMethods, process);
@ -134,8 +141,6 @@ namespace SafeExamBrowser.Applications
instance.WindowsChanged += () => WindowsChanged?.Invoke(); instance.WindowsChanged += () => WindowsChanged?.Invoke();
instance.Initialize(); instance.Initialize();
lock (@lock)
{
instances.Add(instance); instances.Add(instance);
} }
} }