Use mutex to ensure applicationsProgramRun only one instance,CodeAs follows:
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. Windows. forms; Using System. Threading; Using System. runtime. interopservices; Namespace Testplatform { Static Class Program { Private Static Mutex _ mutex = Null ; Private Static String _ Mutexname = " Onlyone_app " ; Private Static String _ Titlename = " Production and testing platform for GPS devices " ; /// <Summary> /// The main entry point of the application. /// </Summary> [Stathread] Static Void Main (){ // Single Instance Try {_ Mutex = Mutex. openexisting (_ mutexname); MessageBox. Show (_ titlename + " Already running. Please confirm! " , " Repeated execution is not allowed. " , Messageboxbuttons. OK, messageboxicon. Stop); intptr _ HANDLE = Findwindow (Null , _ Titlename ); If (_ HANDLE! = Intptr. Zero ){ // MessageBox. Show ("find application ."); Showwindow (_ HANDLE, sw_restore ); // Restore } Application. Exit ();} Catch (Waithandlecannotbeopenedexception ex) // This mutex does not exist {_ Mutex = New Mutex ( True , _ Mutexname); application. enablevisualstyles (); application. setcompatibletextrenderingdefault ( False ); Application. Run ( New Formmain (); _ mutex. releasemutex () ;}} [dllimport ( " User32.dll " )] Private Static Extern Intptr findwindow ( String Classname, String Windowname); [dllimport ( " User32.dll " )] Private Static Extern Bool Showwindow (intptr hwnd, Int Ncmdshow ); Private Const Int Sw_restore = 9 ;}}