判断窗体是否已运行

static System.Threading.Mutex MyMutex;
        /// <summary>
        /// 判断程序是否已运行

        /// </summary>
        private static bool IsMyMutex()
        {
            bool IsExist;
            MyMutex = new System.Threading.Mutex(true, Application.ProductName, out  IsExist);
            if (IsExist)
            {
                return false;
            }
            else
            {
                return true;
            }
        }

 

调用:

 static void Main()
        {
            if (IsMyMutex()) //不允许同一机器同时启动多个
            {
                return;
            }

}

posted @ 2013-05-30 11:17  纵一苇之所如-  阅读(201)  评论(0编辑  收藏  举报