C#进程间的同步,实现只能运行一个程序的效果

using System;
using System.Threading;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool createdNew;
            using (new Mutex(true,Application.ProductName,out createdNew))
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
                else
                {
                    // todo:提示程序已启动
                }
            }
        }
    }
}

 

posted on 2013-06-07 19:04  yao2yao4  阅读(202)  评论(0编辑  收藏  举报

导航