(单例)使用同步基元变量来检测程序是否已运行

static class Program
{
    /// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main()
    {
        var instance = new Mutex(true, "SingleStart", out bool createdNew); //同步基元变量   
        if (createdNew)
        {
            Application.Run(new Form());
            instance.ReleaseMutex();
        }
        else
        {
            Application.Exit();
        }
     }
}
posted @ 2017-08-07 15:03  玮仔Wayne  阅读(148)  评论(0编辑  收藏  举报