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);
}
查看全文
相关阅读:
Window10和Ubuntu 18.04双系统安装的引导问题解决
Linux gcc链接动态库出错:LIBRARY_PATH和LD_LIBRARY_PATH的区别
PaddleBook的部署安全性问题
ubuntu docker中crontab任务不执行的问题
zsh 自动补全导致命令显示重复
For Freedom —— 代理篇
搭建自己私有的PKM系统,各家PKM大比拼。。附:构建自己熟悉的基础Docker,破解联通光猫
Docker上ubuntu新建用户的网络访问不通问题
Android学习杂记
jquery中的工具函数 Utilities
原文地址:https://www.cnblogs.com/scgw/p/1563364.html
最新文章
java 反编译利器JD-JUI
maven profile的使用
Cygwin/babun install telnet
搞懂 SynchronizationContext(第一部分)【翻译】
Maven 最佳实践
maven pom中的repository节点配置没有起作用
Eclipse 调试技巧
kindeditor 去掉网络图片上传功能
CSS 布局口诀
HTML中em与b等的区别
热门文章
eclipse下打包实践
maven package 知识(转载)
JAVA spring hibernate 多数据源配置记录
webapp框架集合
datetimepicker文件
AngularJs-ui modal 封装 dialog
AngularJs-ui modal 传参数
angularjs tips
Python 学习记录
IntelliJ IDEA12.1.1 使用 相关记录
Copyright © 2011-2022 走看看