国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

保證應用程序只有一個實例在運行

2024-07-21 02:20:05
字體:
來源:轉載
供稿:網友
[c#]
public static process runninginstance()
{
process current = process.getcurrentprocess();
process[] processes = process.getprocessesbyname (current.processname);


//loop through the running processes in with the same name
foreach (process process in processes)
{
//ignore the current process
if (process.id != current.id)
{
//make sure that the process is running from the exe file.
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]
public shared function runninginstance() as process
dim current as process = process.getcurrentprocess()
dim processes as process() = process.getprocessesbyname(current.processname)


'loop through the running processes in with the same name
dim process as process
for each process in processes
'ignore the current process
if process.id <> current.id then
'make sure that the process is running from the exe file.
if [assembly].getexecutingassembly().location.replace("/", "/") = current.mainmodule.filename then
'return the other process instance.
return process
end if
end if
next process
'no other instance was found, return null.
return nothing
end function 'runninginstance

如果檢測到已有窗體實例,將此實例顯示出來參考:

[stathread]
static void main()
{
//get the running instance.
process instance = runninginstance();
if (instance == null)
{
//there isn't another instance, show our form.
application.run (new form2());
}
else
{
//there is another instance of this process.
handlerunninginstance(instance);
}
}
public static process runninginstance()
{
process current = process.getcurrentprocess();
process[] processes = process.getprocessesbyname (current.processname);
//loop through the running processes in with the same name
foreach (process process in processes)
{
//ignore the current process
if (process.id != current.id)
{
//make sure that the process is running from the exe file.
if (assembly.getexecutingassembly().location.replace("/", "//") ==current.mainmodule.filename)
{
//return the other process instance.
return process;
}
}
}
//no other instance was found, return null.
return null;
}
public static void handlerunninginstance(process instance)
{
//make sure the window is not minimized or maximized
showwindowasync (instance.mainwindowhandle , ws_shownormal);
//set the real intance to foreground window
setforegroundwindow (instance.mainwindowhandle);
}
[dllimport("user32.dll")]
private static extern bool showwindowasync( intptr hwnd, int cmdshow);
[dllimport("user32.dll")]
private static extern bool setforegroundwindow(intptr hwnd);
private const int ws_shownormal = 1


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 西丰县| 乌审旗| 英超| 和硕县| 城市| 莒南县| 兰西县| 蓬溪县| 肥乡县| 资源县| 清远市| 涿州市| 博乐市| 榆社县| 吉安市| 伊春市| 读书| 博兴县| 东乡| 杭州市| 河池市| 马山县| 邵阳县| 札达县| 平乡县| 临泽县| 武平县| 宝应县| 赣州市| 彭州市| 舞阳县| 厦门市| 天长市| 苏州市| 城市| 商河县| 宜春市| 武义县| 东阿县| 武义县| 伊宁县|