Process activation requirement - Fixed deadlock on shutdown

This commit is contained in:
Robert committed 2021-06-19 14:53:48 +02:00
1 parent f24e1ae264
commit ec69db7201
5 files changed
+14 -19

No files matched your search

@@ -4,7 +4,6 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using Artemis.Core.Services;
using Ninject;
namespace Artemis.Core.Modules
{
@@ -13,8 +12,6 @@ namespace Artemis.Core.Modules
/// </summary>
public class ProcessActivationRequirement : IModuleActivationRequirement
{
private readonly IProcessMonitorService _processMonitorService;
/// <summary>
/// Creates a new instance of the <see cref="ProcessActivationRequirement" /> class
/// </summary>
@@ -25,11 +22,6 @@ namespace Artemis.Core.Modules
if (string.IsNullOrWhiteSpace(processName) && string.IsNullOrWhiteSpace(location))
throw new ArgumentNullException($"Atleast one {nameof(processName)} and {nameof(location)} must not be null");
// Let's not make a habit out of this :P
if (CoreService.Kernel == null)
throw new ArtemisCoreException("Cannot create a ProcessActivationRequirement before initializing the Core");
_processMonitorService = CoreService.Kernel.Get<IProcessMonitorService>();
ProcessName = processName;
Location = location;
}
@@ -44,13 +36,15 @@ namespace Artemis.Core.Modules
/// </summary>
public string? Location { get; set; }
internal static IProcessMonitorService? ProcessMonitorService { get; set; }
/// <inheritdoc />
public bool Evaluate()
{
if (ProcessName == null && Location == null)
if (ProcessMonitorService == null || ProcessName == null && Location == null)
return false;
IEnumerable<Process> processes = _processMonitorService.GetRunningProcesses();
IEnumerable<Process> processes = ProcessMonitorService.GetRunningProcesses();
if (ProcessName != null)
processes = processes.Where(p => string.Equals(p.ProcessName, ProcessName, StringComparison.InvariantCultureIgnoreCase));
if (Location != null)
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Timers;
using Artemis.Core.Modules;
namespace Artemis.Core.Services
{
@@ -22,6 +23,8 @@ namespace Artemis.Core.Services
_processScanTimer.Elapsed += OnTimerElapsed;
_processScanTimer.Start();
_comparer = new ProcessComparer();
ProcessActivationRequirement.ProcessMonitorService = this;
}
public event EventHandler<ProcessEventArgs>? ProcessStarted;
@@ -67,4 +70,4 @@ namespace Artemis.Core.Services
return obj.Id;
}
}
}
}