123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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
- {
- /// <summary>
- /// 全局窗体List,便于相互跳转
- /// </summary>
- public static List<Form> formList = new List<Form>();
- /// <summary>
- /// The main entry point for the application.
- /// </summary>
- [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;
- }
- }
- }
|