国产探花免费观看_亚洲丰满少妇自慰呻吟_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


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 博客| 明水县| 周宁县| 榆中县| 手游| 杭锦旗| 拉萨市| 阳江市| 通道| 乳源| 新闻| 陆丰市| 喀喇| 油尖旺区| 望都县| 玉龙| 清远市| 平顺县| 白沙| 五莲县| 格尔木市| 漳平市| 聂荣县| 寿阳县| 同心县| 固阳县| 漳平市| 高尔夫| 襄垣县| 吴江市| 应城市| 仲巴县| 伽师县| 成安县| 拉萨市| 来安县| 绥宁县| 明星| 兴隆县| 通辽市| 红桥区|