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);
}
查看全文
相关阅读:
第一行代码--笔记(1)
iOS UITableView深入
iOS 数据库主键重复,依然可以插入
UILabel文本高度自适应 不同系统出现问题
UIlabel上的文字 距上 居左 对齐
UILabel 自定义字体
【整理】--VC 编译整理
【整理】--【内核模块】简单例子,编译加载
【原创】-- uboot,kennel,fs,rootfs 编译制作
【原创】-- nfs安装配置及使用,挂载根文件系统
原文地址:https://www.cnblogs.com/xlfj521/p/883909.html
最新文章
android MVP模式初认识-1
PowerDesigner 不同包中实现接口
android 获取512*512规格的图片
android 自定义一个线程池
android 简单的内容观察者代码
android 创建桌面小部件widget
ListView的重用
SoloPi:支付宝开源的 Android 专项测试工具的介绍与快速上手
Airtest介绍与快速上手
微信小程序开发原理与测试注意事项
热门文章
TestNG安装与实例
Python的BeautifulSoup中的HTML结构解析
Python中Beautifulsoup学习笔记二
Python中beautifulsoup学习笔记一
【移动测试时代1.0】Monkeyrunner、Rubotium、UiAutomator、Monkey自动化工具优缺点对比
Axure RP 9 最新版授权与汉化
使用腾讯PerfDog对微信小程序进行性能测试
多字节
OC与js混合开发
des加密算法
Copyright © 2011-2022 走看看