台州海关TD3600上线版本
This commit is contained in:
66
JJMediSys/Program.cs
Normal file
66
JJMediSys/Program.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using DevExpress.Utils.Drawing.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace JJMediSys
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
//Application.EnableVisualStyles();
|
||||
//Application.SetCompatibleTextRenderingDefault(false);
|
||||
//Application.Run(new Login());
|
||||
|
||||
// 定义一个唯一的 Mutex 名称
|
||||
string mutexName = "Global\\JJMediSys";
|
||||
|
||||
// 创建一个全局命名的 Mutex
|
||||
using (Mutex mutex = new Mutex(true, mutexName, out bool isNewInstance))
|
||||
{
|
||||
if (isNewInstance)
|
||||
{
|
||||
// 如果是新的实例,继续启动应用程序
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Login());
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果已经有实例在运行,显示消息或激活已有实例
|
||||
//MessageBox.Show("应用程序已经在运行。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
|
||||
// 尝试找到并激活已有的实例
|
||||
Process currentProcess = Process.GetCurrentProcess();
|
||||
foreach (Process process in Process.GetProcessesByName(currentProcess.ProcessName))
|
||||
{
|
||||
if (process.Id != currentProcess.Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 将焦点切换到已有的实例
|
||||
NativeMethods.SetForegroundWindow(process.MainWindowHandle);
|
||||
break;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 处理可能的异常,例如窗口句柄无效
|
||||
Console.WriteLine($"Error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user