public void ShowDialog() { if (Interlocked.Exchange(ref isDialogOpen, 1) > 0) { return; } using var dlg = new CommitMessageFormatterDlg(); dlg.ShowDialog(); isDialogOpen = 0; }
public CommitMessageFormatterApp() { NotifyIcon = new NotifyIcon { Visible = true, Icon = Resources.comments, ContextMenuStrip = new ContextMenuStrip(), }; NotifyIcon.ContextMenuStrip.Items.AddRange(new ToolStripItem[] { new ToolStripMenuItem("Show", null, (s, e) => ShowDialog()), //new ToolStripMenuItem("Config", null, (s,e) => ShowDialog()), new ToolStripSeparator(), new ToolStripMenuItem("Close", null, (s, e) => ExitThread()), }); NotifyIcon.DoubleClick += (s, e) => ShowDialog(); HotkeyManager = new HotkeyManager(); HotkeyManager.AddHotkey( Keys.F10, ModifierKeys.Alt | ModifierKeys.Shift); HotkeyManager.HotkeyPressed += (s, e) => { if (Interlocked.Exchange(ref isDialogOpen, 1) > 0) { return; } var t = new Thread(() => { using var dlg = new CommitMessageFormatterDlg(); dlg.ShowDialog(); isDialogOpen = 0; }); t.SetApartmentState(ApartmentState.STA); t.Start(); }; }