菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
138
0

Keep Windows Forms Singleton via Mutex key word

原创
05/13 14:22
阅读数 34291
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication3
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            const string appName = "WindowsFormsApplication3";
            bool createdNew;
            Mutex mut = new Mutex(true, appName, out createdNew);
            if (!createdNew)
            {
                MessageBox.Show($"WindowsFormsApplication3 is already running!", "Multiple Instances");
                return;
            }
            Application.Run(new Form1());
        }
    }
}
b

 

发表评论

0/200
138 点赞
0 评论
收藏