From 83a7ea601dcf9053e2d174a2611f9e48242501a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A3=8A?= Date: Sat, 19 Mar 2022 22:33:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AA=E5=85=81=E8=AE=B8=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=AE=9E=E4=BE=8B=E8=BF=90=E8=A1=8C=EF=BC=8C=E5=90=A6=E5=88=99?= =?UTF-8?q?=E7=83=AD=E9=94=AE=E4=BC=9A=E5=86=B2=E7=AA=81=E5=93=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TextLocator/App.xaml.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TextLocator/App.xaml.cs b/TextLocator/App.xaml.cs index d6b4d0e..d172bf7 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"); -- Gitee