Skip to content

Commit

Permalink
Issues #15 Setting "LowLevelHooksTimeout" registry key
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderPro committed Mar 30, 2024
1 parent ebb97c9 commit 1bc7de2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions SmartContextMenu/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,8 @@ static class Program
[STAThread]
static void Main(string[] args)
{
const int LowLevelHooksTimeout = 10000;

AppDomain.CurrentDomain.UnhandledException += OnCurrentDomainUnhandledException;
Application.ThreadException += OnThreadException;

Expand Down Expand Up @@ -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<Window> ProcessCommandLine(CommandLineParser сommandLineParser, ApplicationSettings settings)
Expand Down

0 comments on commit 1bc7de2

Please sign in to comment.