Skip to content

Commit efba394

Browse files
committed
Now handling all exceptions raised while trying to exit the process.
1 parent 86ae08d commit efba394

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

AutoUpdater.NET/AutoUpdater.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -583,34 +583,33 @@ internal static void Exit()
583583
var currentProcess = Process.GetCurrentProcess();
584584
foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName))
585585
{
586-
string processPath;
587-
try
588-
{
589-
processPath = process.MainModule?.FileName;
590-
}
591-
catch (Win32Exception)
586+
if (process.HasExited)
592587
{
593-
// 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.
594-
// This means this is not the process we are looking for so we can safely skip this.
595588
continue;
596589
}
597590

598-
// Get all instances of assembly except current
599-
if (process.Id == currentProcess.Id || currentProcess.MainModule?.FileName != processPath)
591+
try
600592
{
601-
continue;
602-
}
593+
string processPath = process.MainModule?.FileName;
603594

604-
if (process.CloseMainWindow())
605-
{
606-
process.WaitForExit((int)TimeSpan.FromSeconds(10)
607-
.TotalMilliseconds); // Give some time to process message
608-
}
595+
// Get all instances of assembly except current
596+
if (process.Id == currentProcess.Id || currentProcess.MainModule?.FileName != processPath)
597+
{
598+
continue;
599+
}
600+
601+
if (process.CloseMainWindow())
602+
{
603+
process.WaitForExit((int)TimeSpan.FromSeconds(10)
604+
.TotalMilliseconds); // Give some time to process message
605+
}
609606

610-
if (!process.HasExited)
611-
{
612607
process.Kill(); //TODO: Show UI message asking user to close program himself instead of silently killing it
613608
}
609+
catch (Exception)
610+
{
611+
// ignored
612+
}
614613
}
615614

616615
if (ApplicationExitEvent != null)

0 commit comments

Comments
 (0)