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);
}
查看全文
相关阅读:
springboot事物和事物回滚
MyBatis Sql语句中的转义字符
使用 vagrant新建Linux虚拟机
Centos 6.7 安装mongodb
阿里云windows server 2012 TIME_WAIT CLOSE_WAIT
使用Eclipse打jar包 包含依赖jar包
linux crontab定时器
mysql 存储过程学习笔记
oracle windows 新建用户授权 导出导入bmp文件
解决hash冲突的方法
原文地址:https://www.cnblogs.com/scgw/p/1563364.html
最新文章
Day2_冒泡排序bubble sort
Day1_collections库学习
Python爬虫教程【转】
Django1.8以上使用django-groundwork
Angular http服务工具类
Angular版本升级注意事项
Web层通用数据处理之统一异常处理@ExceptionHandler
jackson-annotations之@JsonInclude、@JsonPropertyOrder、@JsonSerialize
IntelliJ IDEA智能编写SQL语句演示
SpringBoot自定义程序启动图标
热门文章
SpringBoot整合Mybatis-Plus自动装配@Autowired失效问题
Spring基本概念整理
Lombok插件安装及介绍
Windows系统下MySQL免安装版演示
Apache Shiro 使用手册(一)Shiro架构介绍
基于Spring框架的Shiro配置
让Apache Shiro保护你的应用
Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot evaluate com.hotel.Object_$$_jvst485_15.toString()
This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has p
springboot统一异常处理类及注解参数为数组的写法
Copyright © 2011-2022 走看看