From 0d7ebe7a8f44abddf22d3e68843588538822dce9 Mon Sep 17 00:00:00 2001 From: liuwf Date: Wed, 30 Oct 2024 11:18:51 +0800 Subject: [PATCH] =?UTF-8?q?add-=E6=9C=97=E8=AF=BB=E5=8F=8A=E6=89=93?= =?UTF-8?q?=E5=8D=B0=E6=9C=8D=E5=8A=A1=E6=B7=BB=E5=8A=A0=E9=98=B2=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E5=90=AF=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PrintBarCode/Startup.cs | 11 +++++++++++ ReadService/Startup.cs | 9 +++++++++ SlnMesnac.WPF/Page/AgvAndTaskMonitorPage.xaml | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/PrintBarCode/Startup.cs b/PrintBarCode/Startup.cs index 5399054..d1a87c3 100644 --- a/PrintBarCode/Startup.cs +++ b/PrintBarCode/Startup.cs @@ -12,6 +12,7 @@ using SlnMesnac.Extensions; using SlnMesnac.Generate; using SlnMesnac.TouchSocket; using SlnMesnac.Redis; +using System.Threading; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -42,12 +43,22 @@ namespace PrintBarCode /// public class Startup { + + private System.Threading.Mutex? mutex = null; /// /// /// /// public Startup(IConfiguration configuration) { + bool ret; + mutex = new System.Threading.Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out ret); + if (!ret) + { + MessageBox.Show("应用程序已开启,禁止重复运行"); + Environment.Exit(0); + } + Configuration = configuration; } diff --git a/ReadService/Startup.cs b/ReadService/Startup.cs index f9639fe..51b6f11 100644 --- a/ReadService/Startup.cs +++ b/ReadService/Startup.cs @@ -13,6 +13,7 @@ using SlnMesnac.Generate; using SlnMesnac.TouchSocket; using ReadService; using SlnMesnac.Redis; +using System.Threading; #region << 版 本 注 释 >> /*-------------------------------------------------------------------- @@ -43,12 +44,20 @@ namespace ConsoleApp /// public class Startup { + private System.Threading.Mutex? mutex = null; /// /// /// /// public Startup(IConfiguration configuration) { + bool ret; + mutex = new System.Threading.Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out ret); + if (!ret) + { + Console.WriteLine("应用程序已开启,禁止重复运行"); + Environment.Exit(0); + } Configuration = configuration; } diff --git a/SlnMesnac.WPF/Page/AgvAndTaskMonitorPage.xaml b/SlnMesnac.WPF/Page/AgvAndTaskMonitorPage.xaml index 6fddac2..eefede7 100644 --- a/SlnMesnac.WPF/Page/AgvAndTaskMonitorPage.xaml +++ b/SlnMesnac.WPF/Page/AgvAndTaskMonitorPage.xaml @@ -40,7 +40,7 @@