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);
}
查看全文
相关阅读:
SQL关键字的执行顺序
StructuredStreaming基础操作和窗口操作
StructuredStreaming简单的例子(NewAPI)
StructuredStreaming(New)
StructuredStreaming编程模型
SparkStreaming简单例子(oldAPI)
SparkStreaming架构
Storm与SparkStreaming对比
SparkStreaming-DStream(Discretized Stream)
史上最全的java随机数生成算法分享(转)
原文地址:https://www.cnblogs.com/scgw/p/1563364.html
最新文章
Java虚拟机系列(二)---HotSpot虚拟机对象
Java虚拟机系列(一)---Java内存划分
Linux学习(一):软链接和硬链接
锋利的JQuery学习之JQuery中的事件
项目中的那些事---时间戳(一)
项目中的那些事---Java反射的应用
数据库操作之Spring JDBCTemplate(postgresql)
锋利的jQuery学习笔记之jQuery选择器
java获取文件大小的方法
Protobuf有没有比JSON快5倍?用代码来击破pb性能神话
热门文章
Google Protocol Buffer 的使用和原理
高并发系统之队列术
FastJson、Jackson、Gson进行Java对象转换Json的细节处理
各个JSON技术的比较(Jackson,Gson,Fastjson)的对比
RabbitMQ学习(一):RabbitMQ要点简介
RabbitMQ学习(二):Java使用RabbitMQ要点知识
转 Hystrix入门指南 Introduction
转 优秀REST风格 API的设计原则
深入理解ajax系列第一篇——XHR对象
Java日期格式转换
Copyright © 2011-2022 走看看