通过GUID确保winform运行唯一实例


通过程序生成的GUIDwinform唯一实例

using System.Threading;bool createdNew;
Guid ownGUID = new Guid(((GuidAttribute)Attribute.GetCustomAttribute(
Assembly.GetExecutingAssembly(),typeof(GuidAttribute))).Value);
Mutex instance = new Mutex(true, ownGUID.ToString("N"), out createdNew);
if (!createdNew) { MessageBox.Show("只能运行唯一实例"); return; }