static System.Threading.Mutex MyMutex;
/// <summary>
/// 判断程序是否已运行
/// </summary>
private static bool IsMyMutex()
{
bool IsExist;
MyMutex = new System.Threading.Mutex(true, Application.ProductName, out IsExist);
if (IsExist)
{
return false;
}
else
{
return true;
}
}
调用:
static void Main()
{
if (IsMyMutex()) //不允许同一机器同时启动多个
{
return;
}
}