Skip to content

Commit

Permalink
[WinForms] Hotkey service exit
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingpie committed Nov 23, 2024
1 parent 837986d commit f42ea82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ internal static class HotkeyManager

static HotkeyManager()
{
// TODO: Thread doesn't exit properly.
Thread messageLoop = new(delegate ()
{
Application.Run(new MessageWindow());
Expand All @@ -39,6 +38,11 @@ static HotkeyManager()
/// </summary>
public static event EventHandler<HotkeyEventArgs> HotkeyPressed = (sender, e) => { };

public static void Exit()
{
Application.Exit();
}

public static int RegisterHotkey(Keys key, KeyModifiers modifiers)
{
_windowReadyEvent.WaitOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Wtq.Services.WinForms;

public class WinFormsHotkeyService : IHostedService
public sealed class WinFormsHotkeyService
: IDisposable, IHostedService
{
private readonly ILogger _log = Log.For<WinFormsHotkeyService>();

Expand Down Expand Up @@ -33,6 +34,11 @@ public WinFormsHotkeyService(IWtqBus bus)
};
}

public void Dispose()
{
HotkeyManager.Exit();
}

public Task StartAsync(CancellationToken cancellationToken)
{
// Only here to make sure an instance of this class is created.
Expand Down

0 comments on commit f42ea82

Please sign in to comment.