From d3135bef8ee7bb8c81f7db0a7ba777b6b350babe Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sun, 23 Mar 2025 14:43:23 +0900 Subject: [PATCH] Add the mutex to avoid redundant --- WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs | 2 ++ WelsonJS.Toolkit/WelsonJS.Launcher/Program.cs | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs index d9680a3..148c966 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/MainForm.cs @@ -38,6 +38,7 @@ namespace WelsonJS.Launcher { e.Cancel = true; this.Hide(); + this.ShowInTaskbar = false; notifyIcon1.Visible = true; } base.OnFormClosing(e); @@ -47,6 +48,7 @@ namespace WelsonJS.Launcher { this.Show(); this.WindowState = FormWindowState.Normal; + this.ShowInTaskbar = true; this.Focus(); notifyIcon1.Visible = false; } diff --git a/WelsonJS.Toolkit/WelsonJS.Launcher/Program.cs b/WelsonJS.Toolkit/WelsonJS.Launcher/Program.cs index 8ace81e..3fc9c6d 100644 --- a/WelsonJS.Toolkit/WelsonJS.Launcher/Program.cs +++ b/WelsonJS.Toolkit/WelsonJS.Launcher/Program.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Threading; using System.Windows.Forms; using WelsonJS.Launcher.Tools; @@ -9,14 +10,24 @@ namespace WelsonJS.Launcher { internal static class Program { + static Mutex mutex; public static ResourceServer resourceServer; [STAThread] static void Main() { + mutex = new Mutex(true, "WelsonJS.Launcher.Mutex", out bool isMutexNotExists); + if (!isMutexNotExists) + { + MessageBox.Show("WelsonJS Launcher already running."); + return; + } + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); + + mutex.ReleaseMutex(); } public static void RunCommandPrompt(string workingDirectory, string entryFileName, string scriptName, bool isConsoleApplication = false, bool isInteractiveServiceAapplication = false)