|
|
|
|
@ -2,6 +2,7 @@ |
|
|
|
|
// Created: 2021-04-23 |
|
|
|
|
// Copyright(c) 2021 SimonG. All Rights Reserved. |
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
|
using System.Collections.Generic; |
|
|
|
|
using System.Diagnostics; |
|
|
|
|
using System.Linq; |
|
|
|
|
@ -55,12 +56,15 @@ namespace Lib.ProcessManaging |
|
|
|
|
if (Processes.Any(p => p.EqualsProcess(process))) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
Processes.Add(_observedProcessFactory.Create(process)); |
|
|
|
|
IObservedProcess observedProcess = _observedProcessFactory.Create(process); |
|
|
|
|
Processes.Add(observedProcess); |
|
|
|
|
ProcessStarted?.Invoke(this, observedProcess); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (var observedProcess in Processes.ToList().Where(p => !Process.GetProcesses().Any(p.EqualsProcess))) |
|
|
|
|
{ |
|
|
|
|
Processes.Remove(observedProcess); |
|
|
|
|
ProcessExited?.Invoke(this, observedProcess); //TestMe: is the passed process still usable? (disposed directly afterwards) |
|
|
|
|
observedProcess.Dispose(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -68,6 +72,9 @@ namespace Lib.ProcessManaging |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public event EventHandler<IObservedProcess>? ProcessStarted; |
|
|
|
|
public event EventHandler<IObservedProcess>? ProcessExited; |
|
|
|
|
|
|
|
|
|
public void Dispose() |
|
|
|
|
{ |
|
|
|
|
Processes.ForEach(p => p.Dispose()); |
|
|
|
|
|