diff --git a/TextLocator/App.xaml.cs b/TextLocator/App.xaml.cs index d6b4d0ea43130124d54f0256160f3432ecc46bcc..d172bf73153b1985b10ddf8d73b0dd10765a2ffd 100644 --- a/TextLocator/App.xaml.cs +++ b/TextLocator/App.xaml.cs @@ -24,6 +24,8 @@ namespace TextLocator public static TaskbarIcon Taskbar { get => _taskbar; set => _taskbar = value; } + System.Threading.Mutex mutex; + public App() { // 初始化线程池大小 @@ -82,6 +84,16 @@ namespace TextLocator protected override void OnStartup(StartupEventArgs e) { + bool ret; + mutex = new Mutex(true, "TextLocator", out ret); + if (!ret) + { + MessageBox.Show("程序已经在运行"); + log.Warn("程序已经在运行"); + AppCore.Shutdown(); + return; + } + // 托盘图标 _taskbar = (TaskbarIcon)FindResource("Taskbar");