static class Program
{
//windows api,用于显示代码
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
//核心代码
Process currProc = Process.GetCurrentProcess();
Process[] runningProc = Process.GetProcesses();
//检查规则,看进程名是否相同。可以自己灵活定制,比如需要检查用户名之类的。
var searchedProc=from a in runningProc
where a.ProcessName == currProc.ProcessName
select a;
if (searchedProc.Count() > 1)
{
//选出和当前进程进程名相同,但是id不同的那个进程
Process firstProc = searchedProc.FirstOrDefault(a => a.Id != currProc.Id);
IntPtr firstProcWindow = firstProc.MainWindowHandle;
SetForegroundWindow(firstProcWindow);
currProc.Kill();
}
//-------end---------
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有