runxinzhi.com
首页
百度搜索
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);
}
相关阅读:
显示屏分辨率自动调整例子
该内存不能read 或written数值 叙述
DELPHI之关于String的内存分配(引)
Delphi关于记录文件的操作转
用句柄操作下拉框
SendMessage参数
c#通过SendMessage发送消息
Delphi内存专题 (引)
Delphi7 中使用ODAC存取图片
打印机状态测试
原文地址:https://www.cnblogs.com/scgw/p/1563364.html
最新文章
手机Android浏览器正式版由百度发布
我们值得您选择的六大优势
QQ电脑管家电脑安全大师
文件夹保护 3000使用教程
轻松复制百度文库内容
秘密的文件夹加密软件超级秘密文件夹
WinRAR 4.10英文正式版
怎样给U盘加密
电脑监控专家专业的电脑监控软件
Windows 一键还原 2012
热门文章
无耻的盗版者:李应伟 姚素霞 景丽
.NET开发常用工具集(不断更新中...)
register_globals使用详解
Visual Studio 2005 SDK Version 4.0
Create Elegant Code with Anonymous Methods, Iterators, and Partial Classes
osCommerce Tutorials
VS 2008 & .NET Framework 3.5 Training Kit
Early vs. Late Binding
“三步走”成为一名优秀的程序员
How release file loaded with Assembly.LoadFrom() ?
Copyright © 2020-2023
润新知