C# 避免程序重复启动(二次启动)

 

采用近程互斥的方法。

[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();

    }
                    
}

 

以上代码可以用来避免程序的二次启动。

你可能感兴趣的:(C#)