C#检测是否已经运行了一个当前的程序【搜藏】

   using System.Threading;

       [STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            //限制该程序只能运行一个实例
            //Create a new mutex using specific mutex name

            bool bCreatedNew;

            Mutex m = new Mutex(false, "bxSys.exe", out bCreatedNew);

            if (bCreatedNew) //未运行

                Application.Run(new MainForm());

            else

            {

                MessageBox.Show("该程序已经运行!");

                return;

            }

        }
posted @ 2011-03-26 13:53  与卡  阅读(1703)  评论(0编辑  收藏  举报