- add processStarted and processExited event

master
Simon G 5 years ago
parent 63b392fa77
commit e396fbfb60
  1. 3
      Lib.ProcessManaging/Interfaces/IProcessManager.cs
  2. 9
      Lib.ProcessManaging/ProcessManager.cs

@ -12,5 +12,8 @@ namespace Lib.ProcessManaging.Interfaces
List<IObservedProcess>? Processes { get; }
void Initialize();
event EventHandler<IObservedProcess>? ProcessStarted;
event EventHandler<IObservedProcess>? ProcessExited;
}
}

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

Loading…
Cancel
Save