diff --git a/AutoUpdater.NET/AutoUpdater.cs b/AutoUpdater.NET/AutoUpdater.cs index 030e45e..685df31 100644 --- a/AutoUpdater.NET/AutoUpdater.cs +++ b/AutoUpdater.NET/AutoUpdater.cs @@ -583,34 +583,33 @@ internal static void Exit() var currentProcess = Process.GetCurrentProcess(); foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName)) { - string processPath; - try - { - processPath = process.MainModule?.FileName; - } - catch (Win32Exception) + if (process.HasExited) { - // Current process should be same as processes created by other instances of the application so it should be able to access modules of other instances. - // This means this is not the process we are looking for so we can safely skip this. continue; } - // Get all instances of assembly except current - if (process.Id == currentProcess.Id || currentProcess.MainModule?.FileName != processPath) + try { - continue; - } + string processPath = process.MainModule?.FileName; - if (process.CloseMainWindow()) - { - process.WaitForExit((int)TimeSpan.FromSeconds(10) - .TotalMilliseconds); // Give some time to process message - } + // Get all instances of assembly except current + if (process.Id == currentProcess.Id || currentProcess.MainModule?.FileName != processPath) + { + continue; + } + + if (process.CloseMainWindow()) + { + process.WaitForExit((int)TimeSpan.FromSeconds(10) + .TotalMilliseconds); // Give some time to process message + } - if (!process.HasExited) - { process.Kill(); //TODO: Show UI message asking user to close program himself instead of silently killing it } + catch (Exception) + { + // ignored + } } if (ApplicationExitEvent != null)