/// <summary> /// 根据进程映像路径名称激活指定进程 /// </summary> /// <param name="aProcessPath"></param> public static void BringProcessToFrontByPath(string aProcessPath) { //检测进程是否已经重复启动 System.Diagnostics.Process[] processList = System.Diagnostics.Process.GetProcesses(); Process current = Process.GetCurrentProcess(); foreach (System.Diagnostics.Process process in processList) { if (process.Id != current.Id) { //比较进程名如"CenterSystem" if (process.ProcessName.ToUpper() == System.IO.Path.GetFileNameWithoutExtension(aProcessPath).ToUpper()) { IntPtr hWnd = process.MainWindowHandle; // if iconic, we need to restore the window if (UtilityTool.IsIconic(hWnd)) //如果窗体最小化,则恢复窗体 { UtilityTool.ShowWindowAsync(hWnd, UtilityTool.SW_RESTORE); } //SetWindowPos(hWnd, new IntPtr(-1), 0, 0, 0, 0, 1 | 2); //激活窗体并置前 UtilityTool.SetForegroundWindow(hWnd); return; } } } }
//Udp广播发送数据 private bool SendData(UdpClient client, IPEndPoint endpoint, byte[] data, ref string strErr) { strErr = ""; if (endpoint == null) { strErr = "IPEndPoint cannot be null"; return(false); } if (!IsOpen) { strErr = "UdpClient is not opened"; return(false); } try { IsStop = false; int sendCount = client.Send(data, data.Length, endpoint); if (sendCount != data.Length) { strErr = string.Format("send data:{0} falied!{2}", StrUtils.BytesToHexStr(data), UtilityTool.GetSysErrMsg()); return(false); } } catch (Exception e) { strErr = string.Format("UdpClient({0}) send data failed:{1}", client?.Client?.LocalEndPoint, e.Message); return(false); } return(true); }