From 7a5a6b7d6385603566ebfb65a4b895b7be7bd82a Mon Sep 17 00:00:00 2001 From: Si13n7 Date: Thu, 21 Jun 2018 21:36:28 +0200 Subject: [PATCH] Fix critical issue that can cause an infinite loop. --- src/AppsLauncher/Program.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/AppsLauncher/Program.cs b/src/AppsLauncher/Program.cs index 82c4d33..53a7e91 100644 --- a/src/AppsLauncher/Program.cs +++ b/src/AppsLauncher/Program.cs @@ -1,6 +1,7 @@ namespace AppsLauncher { using System; + using System.Diagnostics; using System.Linq; using System.Threading; using System.Windows.Forms; @@ -87,13 +88,15 @@ private static void Main() if (!Arguments.ValidPaths.Any()) return; + IntPtr hWnd; + var stopwatch = new Stopwatch(); + stopwatch.Start(); do - { hWnd = Reg.Read(Settings.RegistryPath, "Handle", IntPtr.Zero); - } - while (hWnd == IntPtr.Zero); - WinApi.NativeHelper.SendArgs(hWnd, Arguments.ValidPathsStr); + while (hWnd == IntPtr.Zero && stopwatch.Elapsed.TotalSeconds <= 10); + if (hWnd != IntPtr.Zero) + WinApi.NativeHelper.SendArgs(hWnd, Arguments.ValidPathsStr); } } }