欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Keep Windows Forms Singleton via Mutex key word

程序员文章站 2022-03-25 17:35:09
using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; n ......
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