The following lists common methods:
1,
Static void main ()
{
Bool initiallyowned = true;
Bool iscreated;
Mutex M = new mutex (initiallyowned, "mytest", out iscreated );
If (! (Initiallyowned & iscreated ))
{
MessageBox. Show ("the same instance is already running. "," Prompt ", messageboxbuttons. OK, messageboxicon. information );
Application. Exit ();
}
Else
{
Application. Run (New mainform ());
}
}
2,
Static void main ()
{
Int proceedingcount = 0;
Process [] proceddingcon = process. getprocesses ();
Foreach (process isprocedding in proceddingcon)
{
If (isprocedding. processname = process. getcurrentprocess (). processname)
{
Proceedingcount + = 1;
}
}
If (proceedingcount> 1)
{
MessageBox. Show ("the system is running. "," Prompt ", messageboxbuttons. OK, messageboxicon. information );
}
Else
{
Application. enablevisualstyles ();
Application. doevents ();
Application. Run (New mainform ());
}
}
3,
Private Static bool checkinstance ()
{
String procname = system. Diagnostics. process. getcurrentprocess (). processname;
If (system. Diagnostics. process. getprocessesbyname (procname). getupperbound (0)> 0)
{
Return true;
}
Else
{
Return false;
}
}
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/xiekun2008/archive/2008/11/26/3381159.aspx