zoukankan      html  css  js  c++  java
  • c#实现程序的互斥运行

    Process currentProcess = Process.GetCurrentProcess(); //获取当前进程
    //获取当前运行程序完全限定名
    //string currentFileName = Path.GetFileName(currentProcess.MainModule.FileName);
    string currentFileName = currentProcess.ProcessName;
    //获取进程名为ProcessName的Process数组。
    Process[] processes = Process.GetProcessesByName(currentProcess.ProcessName);
    //遍历有相同进程名称正在运行的进程
    foreach (Process process in processes)
    {
     if (process.ProcessName == currentFileName)
     {
      if (process.Id != currentProcess.Id) //根据进程ID排除当前进程
      {
       MessageBox.Show(null, "程序已经运行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
       return;//退出实例
      }
       
     }
    }

    这段带只是实现了同名程序的互斥运行,要想实现任意的程序互斥运行,只要改变判断的条件即可。
  • 相关阅读:
    JavaScript数组方法--includes、indexOf、lastIndexOf
    JavaScript数组方法--flat、forEach、map
    JavaScript数组方法--filter、find、findIndex
    bootstrap-14
    bootstrap-13
    bootstrap-12
    bootstrap-11
    bootstrap-10
    bootstrap-9
    bootstrap-8
  • 原文地址:https://www.cnblogs.com/niceboy/p/814653.html
Copyright © 2011-2022 走看看