From 773b4fad8816133d7c9a11453df401e04984daf8 Mon Sep 17 00:00:00 2001 From: Paul Woolcock <11843015+phw198@users.noreply.github.com> Date: Mon, 23 Oct 2023 00:46:43 +0100 Subject: [PATCH] Only compare processes with different PID to current. #1717 --- src/OutlookGoogleCalendarSync/Program.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/OutlookGoogleCalendarSync/Program.cs b/src/OutlookGoogleCalendarSync/Program.cs index c3c3d2be..09be3bca 100644 --- a/src/OutlookGoogleCalendarSync/Program.cs +++ b/src/OutlookGoogleCalendarSync/Program.cs @@ -659,17 +659,21 @@ public static void StackTraceToString() { private static void instancesRunning() { try { System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess(); - String currentCmdLine = getProcessCommandLine(currentProcess.Id); - System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName(currentProcess.ProcessName); if (processes.Count() > 1) { log.Warn("There are " + processes.Count() + " " + currentProcess.ProcessName + " processes currently running."); List> sameExe = processes.GroupBy(p => p.MainModule.FileName).Where(e => e.Count() > 1).ToList(); log.Debug(sameExe.Count() + " executables have more than one process attached; checking runtime arguments"); + log.Debug("Current process command line:-"); + String currentCmdLine = getProcessCommandLine(currentProcess.Id); + foreach (System.Linq.IGrouping exe in sameExe) { + log.Debug("Checking other processes running the same executable:-"); log.Debug(exe.Key); foreach (System.Diagnostics.Process process in exe) { + if (process.Id == currentProcess.Id) continue; + String cmdLine = getProcessCommandLine(process.Id); if (cmdLine == currentCmdLine) { OgcsMessageBox.Show("You already have an instance of OGCS running using the same configuration.\r\n" + @@ -678,6 +682,7 @@ private static void instancesRunning() { return; } } + log.Debug("OK - they are running with different configurations."); } }