using System; using System.Xml; using System.ComponentModel; using System.Windows.Forms; using System.Diagnostics; using System.Runtime; using System.Reflection; using System.Runtime.InteropServices; [STAThread] static void Main () // Main program run {process intance = runningintance (); // Call the check function if (intance == null) // does not exist the same program {Application.Run (new frmmain ());} else // There is the same program {HandleRunningInstance (intance);}} private static Process RunningIntance () {Process currentProcess = Process.GetCurrentProcess (); Process [] processCollection = Process.GetProcessesByName (currentProcess.ProcessName); foreach (Process p in processCollection) {if (p .Id! = Currentprocess.id) // Check if the ID is the same {// check the run file path is the same IF (askSEMBLY.GETEXECUTISSEMBLY (). Location.Replace ("/", "//") == CurrentProcess.mainmodule. Filename) Return CurrentProcess;}} Return NULL;} procate static void handlerunninginstance ("The application system (PSP) is already running!", "Tips", ME SSAGEBOXBUTTONS.OK, MessageBoxicon.information; ShowWindowasync (Instance.MainWindowHandle, 1); // Call the API function, normal display window setForegroundWindow (instance.mainwindowhandle); // Place the front end of the window. } [DllImport ( "User32.dll")] private static extern bool ShowWindowAsync (System.IntPtr hWnd, int cmdShow); [DllImport ( "User32.dll")] private static extern bool SetForegroundWindow (System.IntPtr hWnd);