There are many solutions. First, the most silly one:
Static class Program
{
/// <Summary>
/// Main entry point of the application.
/// </Summary>
[STAThread]
Static void Main ()
{
If (System. Diagnostics. Process. GetProcessesByName (System. Diagnostics. Process. GetCurrentProcess (). ProcessName). Length> 1)
{
MessageBox. Show ("one already runs ");
}
Else
{
Application. Run (new Form1 ());
}
}
}
Another type
Static class Program
{
[STAThread ()]
Public static void Main ()
{
Bool ret;
System. Threading. Mutex m = newSystem. Threading. Mutex (true, Application. ProductName, out ret );
If (ret)
{
// System. Windows. Forms. Application. EnableVisualStyles (); // these two lines implement the XP visual style.
// System. Windows. Forms. Application. DoEvents ();
System. Windows. Forms. Application. Run (new Form1 ());
// FrmMain is the main form of your program. This is not required for console programs.
M. ReleaseMutex ();
}
Else
{
MessageBox. Show (null, "one application with the same program is already running. Please do not run multiple programs at the same time. The program \ n is about to exit. ", Application. ProductName, MessageBoxButtons. OK, MessageBoxIcon. Warning );
// Message, which can be deleted.
Application. Exit (); // Exit the program
}
}
}