zoukankan      html  css  js  c++  java
  • 单实例运行程序

    代码

    using System;
    using System.Threading;

    namespace SignleApplication
    {
        
    class Program
        {
            
    /// <summary>
            
    /// 定义信号量,只能运行单实例
            
    /// </summary>
            static Mutex mutex=new Mutex(false,"control.mutext");
            
            
    public static void Main(string[] args)
            {
                
    if(!mutex.WaitOne(TimeSpan.FromSeconds(5),false))
                {
                    Console.WriteLine(
    "当前实例在运行!");
                }
                Console.WriteLine(
    "Hello World!");
                
                
    try
                {
                
    // TODO: Implement Functionality Here
                
                Console.Write(
    "Press any key to continue . . . ");
                Console.ReadKey(
    true);
                }
                
    finally
                {
                    mutex.ReleaseMutex();
                }
            }
        }
    }
  • 相关阅读:
    从进入这里,没有写过什么文章,现在开始吧
    24)
    23)
    22)
    21)
    20)
    19)
    18)
    17)
    16)
  • 原文地址:https://www.cnblogs.com/csharponworking/p/1643380.html
Copyright © 2011-2022 走看看