防止应用程序重复打开

using ReadCardService.ServiceBus;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using PurClient.Logging;

namespace ReadCardService.WinUI
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{

//System.Threading.Mutex mutex = new System.Threading.Mutex(false, "应用程序的程序集GUID号");
System.Threading.Mutex mutex = new System.Threading.Mutex(false, "e8feb7e7-e733-46a6-8afe-365e224dd1c7");

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
bool running = !mutex.WaitOne(0, false);
if (!running)
{
Application.Run(new FormLogs());
}
else
{
MessageBox.Show("程序已经启动,请勿重复打开");
}


}
}
}

posted @ 2018-02-06 14:21  姚小丹  阅读(527)  评论(0编辑  收藏  举报