Loading

C# 避免程序重复启动

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool ret;
            Mutex mutex = new Mutex(true, Application.ProductName, out   ret);
            if (ret)
            {
                Application.Run(new Form1());
            }
            else
            {
                MessageBox.Show("该程序已经启动", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            
        }
    }
}

转自https://www.cnblogs.com/LicwStack/p/8587352.html

posted @ 2019-12-07 11:36  WeiYongZhi  阅读(252)  评论(0编辑  收藏  举报