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);
}
查看全文
相关阅读:
TCP心跳包
interesting site
TestNG环境搭建以及框架初识
lambda表达式
subprocess学习
使用psutil模块获取电脑运行信息
使用ssh和putty操控远程的linux server
ubuntu系统源的更新
将python的程序包装成windows下的service
使用python进行re拆分网页内容
原文地址:https://www.cnblogs.com/scgw/p/1563364.html
最新文章
redis线程问题 相关配置
js中this,箭头函数和普通函数
前端 9.16腾讯-2019校园招聘(正式卷)编程题题解(js)
《JavaScript高级程序设计》读书笔记(五)引用类型
《JavaScript高级程序设计》读书笔记(四)变量、作用域和内存问题
值传递和引用传递
《JavaScript高级程序设计》读书笔记(三)基本概念第六小节理解函数
《JavaScript高级程序设计》读书笔记(三)基本概念第五小节流程控制语句
《JavaScript高级程序设计》读书笔记(三)基本概念第四小节 操作符
《JavaScript高级程序设计》读书笔记(三)基本概念第二小节 Number类型
热门文章
字符串中的字母大小写转换、生成随机字符串
字符串与十六进制数的相互转换
信号函数
Linux中文件函数(二)
Linux中文件函数(一)
netstat命令的用法
Linux中文件I/O函数
实现一个shell程序
exec函数族
读写锁
Copyright © 2011-2022 走看看