判断该程序是否已有实例运行

using  System.Diagnostics;


namespace  Assistant.Common
{
    
/// 
    
/// 进程工具类
    
/// 

    public class ProcessUtil
    
{
        
/// 
        
/// 判断该程序是否已有实例运行
        
/// 

        
/// 实例文件名
        
/// 是否有运行实例

        public static bool HasRunningInstance(string fileName)
        
{
            Process current 
= Process.GetCurrentProcess();
            Process[] processes 
= Process.GetProcessesByName(current.ProcessName);

            
foreach (Process process in processes)
            
{
                
if (process.Id != current.Id)
                
{
                    
if (fileName.Replace("/""/"== current.MainModule.FileName)
                    
{
                        
return true;
                    }

                }

            }


            
return false;
        }

    }

}
 

你可能感兴趣的:(判断该程序是否已有实例运行)