欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#確保只有一個(gè)實(shí)例在運(yùn)行的方法

 更新時(shí)間:2015年05月14日 12:29:34   作者:兩把刷子  
這篇文章主要介紹了C#確保只有一個(gè)實(shí)例在運(yùn)行的方法,涉及C#進(jìn)程操作的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了C#確保只有一個(gè)實(shí)例在運(yùn)行的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

public static Process RunningInstance() 
{ 
Process current = Process.GetCurrentProcess(); 
Process[] processes = Process.GetProcessesByName (current.ProcessName); 
//查找相同名稱(chēng)的進(jìn)程 
foreach (Process process in processes) 
{ 
//忽略當(dāng)前進(jìn)程 
if (process.Id != current.Id) 
{ 
//確認(rèn)相同進(jìn)程的程序運(yùn)行位置是否一樣. 
if (Assembly.GetExecutingAssembly().Location.Replace("/", "\\") == current.MainModule.FileName) 
{ 
//Return the other process instance. 
return process; 
} 
} 
} 
//No other instance was found, return null. 
return null; 
} 
[VB.NET] 

希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論