C#检查单个实例

2021-04-24 21:29

阅读:409

标签:static   ext   sse   pat   nbsp   pdo   second   run   kill   

        public static Process RunningInstance()
        {
            Process currentProcess = Process.GetCurrentProcess();
            Process[] sameProcess = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(AppDomain.CurrentDomain.BaseDirectory + currentProcess.ProcessName));
            if (sameProcess != null && sameProcess.Length > 0)
            {
                // 遍历正在有相同名字运行的例程     
                foreach (Process process in sameProcess)
                {   
                    // 忽略现有的例程  
                    if (process.Id != currentProcess.Id && (process.StartTime - currentProcess.StartTime).TotalMilliseconds                     {
                        process.Kill();
                        return null;
                        //return process;
                    }
                }
            }
            return null;
        }

C#检查单个实例

标签:static   ext   sse   pat   nbsp   pdo   second   run   kill   

原文地址:http://www.cnblogs.com/yi-u/p/7940321.html


评论


亲,登录后才可以留言!