程序多开检测代码

public static void CheckMutilApp()
        {
            var myProc = System.Diagnostics.Process.GetCurrentProcess();
            var allProcs = System.Diagnostics.Process.GetProcesses();
            int count = 0;
            foreach (var proc in allProcs)
            {
                try
                {
                    if (myProc.ProcessName == proc.ProcessName)
                        count++;
                }
                catch
                {
                   
                }
            }
            if (count == 2)
            {
                throw new Exception("检测到程序重复打开!");
            }

            if (count >= 2)
            {
                Environment.Exit(0);
            }
        }

 

程序多开检测代码

上一篇:中小型网络架构-自用备忘


下一篇:[LeetCode] 1904. The Number of Full Rounds You Have Played