zoukankan      html  css  js  c++  java
  • 让你的程序只运行一个实例(二)

    使用线程互斥变量. 通过定义互斥变量来判断是否已运行实例

            [STAThread]
            static void Main() {
                //是否已经运行了实例
                bool runone;
                System.Threading.Mutex run = new System.Threading.Mutex(true, "FormsEditor", out runone);
                if(runone)
                {
                    run.ReleaseMutex();
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
                }
                else
                {
                    MessageBox.Show("已经运行了一个实例了。");
                }
     
            }
  • 相关阅读:
    try_files $uri $uri/ /index.php?$query_string;
    关于declare(strict_types=1)的有效范围
    SVN客户端安装与使用
    Java日志框架中真的需要判断log.isDebugEnabled()吗?
    Spring4自动装配(default-autowire)
    java的@PostConstruct注解
    Google Guava之--cache
    Java类加载机制与Tomcat类加载器架构
    搞懂JVM类加载机制
    Java 类加载机制
  • 原文地址:https://www.cnblogs.com/ITBread/p/2584968.html
Copyright © 2011-2022 走看看