如何限制用户只打开一次Windows应用程序

问题描述:

如何限制用户只打开Windows应用程序单个实例

how can restrict the user to open windows application only single instance

尝试在"Program.cs"中添加以下代码。

Try to add the following code in "Program.cs".

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        bool blnIsRunning;
        Mutex mutexApp = new Mutex(false, Assembly.GetExecutingAssembly().FullName, out blnIsRunning);
        if (!blnIsRunning)
        {
            MessageBox.Show("Is Running!", "Warning",
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            return;
        }
        Application.Run(new Form1());
    }

结果:

问候,

Kyle