private static Process RunningInstance() { Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName(current.ProcessName); //遍历与当前进程名称相同的进程列表 foreach (Process process in processes) { //如果实例已经存在则忽略当前进程 if (process.Id != current.Id) { //保证要打开的进程同已经存在的进程来自同一文件路径 if (Assembly.GetExecutingAssembly().Location.Replace("/", @"\") == current.MainModule.FileName) { //返回已经存在的进程 return process; } } } return null; } [DllImport("User32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); //3.已经有了就把它激活,并将其窗口放置最前端 private static void HandleRunningInstance(Process instance) { MessageHelper.ShowTips("当前程序已经被打开,无法重复打开!"); SetForegroundWindow(instance.MainWindowHandle); //尝试将窗口放置最前端 }