判断程序是否运行的代码 (有点单例模式的味道)

           

            string moduleName = Process.GetCurrentProcess().MainModule.ModuleName;
            string processName = System.IO.Path.GetFileNameWithoutExtension(moduleName);
            Process[] processes = Process.GetProcessesByName(processName);
            if (processes.Length > 1)
            {
                MessageBox.Show("程序已经运行!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }

      这段代码确实有种变相的单例模式的味道,不过好象一段代码,缺少了点AI的味道,应该把当前的那个实例调用出来就会更好了...

posted on 2009-06-01 17:32  Mike Mao  阅读(247)  评论(0编辑  收藏  举报

导航