采用近程互斥的方法。
[STAThread]
static void Main( string [] args)
... {
bool requestInitialOwnership = true;
bool mutexWasCreated;
Mutex m = new Mutex(requestInitialOwnership,"MyMutex",out mutexWasCreated);
if(!mutexWasCreated)
...{
Application.Run(new frmProdMenu());
m.ReleaseMutex();
}
}
static void Main( string [] args)
... {
bool requestInitialOwnership = true;
bool mutexWasCreated;
Mutex m = new Mutex(requestInitialOwnership,"MyMutex",out mutexWasCreated);
if(!mutexWasCreated)
...{
Application.Run(new frmProdMenu());
m.ReleaseMutex();
}
}
以上代码可以用来避免程序的二次启动。