Using system; using system. Windows. forms; using system. runtime. interopservices; // required to use dllimport. Using system. diagnostics; // introduce the namespace of the process class {static class program {private const int ws_shownormal = 1; [dllimport ("user32.dll")] Private Static extern bool showwindowasync (intptr hwnd, int cmdshow); [dllimport ("user32.dll")] Private Static extern bool setforegroundwindow (intptr hwnd); // <summary> // Application Program . /// </Summary> [stathread] Static void main () {process instance = getrunninginstance (); If (instance = NULL) {application. enablevisualstyles (); application. setcompatibletextrenderingdefault (false); application. run (New frm_main (); // start the main form here.} Else {handlerunninginstance (Instance) ;}/// <summary> // obtain whether the same process exists. /// </Summary> /// <returns> </returns> Public static process getrunninginstance () {process current = process. getcurrentprocess (); Process [] processes = process. getprocessesbyname (current. processname); // traverses the routine foreach (Process in processes) that is running with the same name {// ignore the existing routine if (process. ID! = Current. ID) // make sure that the routine runs if (system. reflection. assembly. getexecutingassembly (). location. replace ("/", "\") = current. mainmodule. filename) return process;} return NULL;} // <summary> // activate the original process. /// </Summary> /// <Param name = "instance"> </param> Public static void handlerunninginstance (process instance) {showwindowasync (instance. mainwindowhandle, ws_shownormal); setforegroundwindow (instance. main1_whandle );}}}