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 <= 0)
                    {
                        process.Kill();
                        return null;
                        //return process;
                    }
                }
            }
            return null;
        }

版权声明:本文为yi-u原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:http://www.cnblogs.com/yi-u/p/7940321.html