using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Threading.Tasks; using System.Windows.Forms; namespace ShareWifi { static class Program { /// /// 全局窗体List,便于相互跳转 /// public static List
formList = new List(); /// /// The main entry point for the application. /// [STAThread] static void Main() { Process instance = RunningInstance(); if (instance == null) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); } else { // MessageBox.Show("程序已经在运行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } } public 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; } } } // 如果没有其他同名进程存在,则返回 null return null; } } }