Test
{
    /// <summary>
    
/// 应用程序的主入口点。
    
/// </summary>
    [STAThread]

    
static void Main(string[] args)
    {
        
bool flag = false;
        System.Threading.Mutex mutex 
= new System.Threading.Mutex(true"Test"out flag);
        
//第一个参数:true--给调用线程赋予互斥体的初始所属权
        
//第一个参数:互斥体的名称
        
//第三个参数:返回值,如果调用线程已被授予互斥体的初始所属权,则返回true
        if (flag)
        {
            Console.Write(
"Running");
        }
        
else
        {
            Console.Write(
"Another is Running");
            System.Threading.Thread.Sleep(
5000);//线程挂起5秒钟
            Environment.Exit(1);//退出程序
        }
        Console.ReadLine();
    }
}

相关文章:

  • 2021-06-13
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-06-27
  • 2022-12-23
  • 2022-03-01
猜你喜欢
  • 2021-12-02
  • 2021-12-09
  • 2022-02-08
  • 2022-12-23
相关资源
相似解决方案