From 1bc7de2a3d836e08b5c2e3794ce1f09eedb5fb3f Mon Sep 17 00:00:00 2001 From: AlexanderPro Date: Sat, 30 Mar 2024 18:18:42 +0300 Subject: [PATCH] Issues #15 Setting "LowLevelHooksTimeout" registry key --- SmartContextMenu/Program.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/SmartContextMenu/Program.cs b/SmartContextMenu/Program.cs index 1fce0ad..7e0a913 100644 --- a/SmartContextMenu/Program.cs +++ b/SmartContextMenu/Program.cs @@ -5,6 +5,7 @@ using System.Linq; using System.IO; using System.Drawing.Imaging; +using Microsoft.Win32; using SmartContextMenu.Forms; using SmartContextMenu.Utils; using SmartContextMenu.Extensions; @@ -22,6 +23,8 @@ static class Program [STAThread] static void Main(string[] args) { + const int LowLevelHooksTimeout = 10000; + AppDomain.CurrentDomain.UnhandledException += OnCurrentDomainUnhandledException; Application.ThreadException += OnThreadException; @@ -58,9 +61,30 @@ static void Main(string[] args) return; } + var lowLevelHooksTimeoutString = commandLineParser.GetToggleValueOrDefault(nameof(LowLevelHooksTimeout), null); + var lowLevelHooksTimeoutValue = int.TryParse(lowLevelHooksTimeoutString, out var value) ? value : LowLevelHooksTimeout; + + using var key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop\\", true); + var lowLevelHooksTimeoutOldString = key?.GetValue(nameof(LowLevelHooksTimeout))?.ToString(); + var lowLevelHooksTimeoutOldValue = int.TryParse(lowLevelHooksTimeoutOldString, out var oldValue) ? oldValue : (int?)null; + + if (lowLevelHooksTimeoutValue > lowLevelHooksTimeoutOldValue || lowLevelHooksTimeoutOldValue == null) + { + key.SetValue(nameof(LowLevelHooksTimeout), lowLevelHooksTimeoutValue); + } + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(settings, windows.ToArray())); + + if (lowLevelHooksTimeoutOldValue != null) + { + key.SetValue(nameof(LowLevelHooksTimeout), lowLevelHooksTimeoutOldValue); + } + else + { + key.DeleteValue(nameof(LowLevelHooksTimeout)); + } } static ICollection ProcessCommandLine(CommandLineParser сommandLineParser, ApplicationSettings settings)