Keep Windows Forms Singleton via Mutex key word

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

 

上一篇:关于网络连接方式的总结(HostOnly,NAT....)


下一篇:[TMI2018-03]Multimodal MR Synthesis via Modality-Invariant Latent Representation