首页 > 解决方案 > 使用 Mutex c#.net 打开/显示表单

问题描述

如果表单已经存在,有没有办法打开/显示表单?我使用 Mutex 来检查我的应用程序的实例是否打开。

这是我的 program.cs 文件的代码。


 static void Main() {
            bool InstanceCount = false;

            using (Mutex m = new Mutex(true, "MyRunningApp", out InstanceCount)) {
                if (InstanceCount) {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Main());
                    m.ReleaseMutex();
                }

                else {
                    MessageBox.Show("Power Monitor is Already RUNNING, Please Check the System Tray.");
                }
            }
        }

我试过 Show(); 但它给了我这个错误“当前上下文中不存在名称'show'”。

标签: c#winforms

解决方案


推荐阅读