应用程序单例运行

通过进程互斥实现,利用程序集guid作为进程标识.即使用户修改了可执行文件的文件名,也不会影响单例运行.

代码如下:

bool Run =false;
string Name = ((GuidAttribute)Assembly.GetEntryAssembly().GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value;
Mutex Mutex 
=new Mutex(true, Name, out Run);
if (Run)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(
false); 
Application.Run(...);
}

原文地址:https://www.cnblogs.com/wangmingjin/p/2125172.html