zoukankan
html css js c++ java
C#程序多用户只启动一个进程的方法
Main函数
[STAThread]
static
void
Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(
false
);
webscreenshot wb
=
new
webscreenshot();
Process current
=
Process.GetCurrentProcess();
bool
newinstance
=
true
;
Process[] processes
=
Process.GetProcessesByName(current.ProcessName);
//
遍历正在有相同名字运行的例程
foreach
(Process process
in
processes)
{
//
忽略现有的例程
if
(process.Id
!=
current.Id)
{
//
确保例程从EXE文件运行
if
(Assembly.GetExecutingAssembly().Location.Replace(
"
/
"
,
"
\\
"
)
==
current.MainModule.FileName)
{
//
返回另一个例程实例
current
=
process;
newinstance
=
false
;
break
;
}
}
}
if
(newinstance)
{
Application.Run(wb);
}
else
{
ShowWindowAsync(current.MainWindowHandle,
1
);
//
设置真实例程为foreground window
SetForegroundWindow(current.MainWindowHandle);
}
}
引入这两个API函数
[DllImport(
"
User32.dll
"
)]
private
static
extern
bool
ShowWindowAsync( IntPtr hWnd,
int
cmdShow);
[DllImport(
"
User32.dll
"
)]
private
static
extern
bool
SetForegroundWindow(IntPtr hWnd);
}
查看全文
相关阅读:
bzoj1711
bzoj1458
bzoj1433
hdu2732
bzoj1066
hdu3549
poj1698
[ZJOI2007]时态同步
SA 学习笔记
[LUOGU]2016 Sam数
原文地址:https://www.cnblogs.com/xlfj521/p/883909.html
最新文章
jQuery .tmpl(), .template()学习资料小结
SQL Server存储过程 对数组参数的循环处理
网上收藏的几个邹老大的分页存储过程
把存储过程SELECT INTO到临时表
存储过程表的循环
Sql中判断"数据库"、"表"、"临时表"、"存储过程"和列"是否存在
存储过程中使用事务与try catch
LeetCode:Contains Duplicate Ⅲ
LeetCode:Contains Duplicate II
LeetCode:Contains Duplicate
热门文章
LeetCode:Implement strStr()
[转July]KMP算法(mark)
[转]KMP算法
LeetCode:Reverse words in a String
LeetCode:Valid Number
LeetCode:Valid Palindrome(need update)
LeetCode:3Sum Closet
bzoj2929
hdu4309
hdu1569
Copyright © 2011-2022 走看看