|
@@ -5,6 +5,7 @@ using IWshRuntimeLibrary; |
|
|
using Microsoft.Web.WebView2.Wpf; |
|
|
using Microsoft.Web.WebView2.Wpf; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json; |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.Collections; |
|
|
using System.Collections.Concurrent; |
|
|
using System.Collections.Concurrent; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.Diagnostics; |
|
|
using System.Diagnostics; |
|
@@ -168,12 +169,35 @@ namespace BPASmartClient.ScreenLib |
|
|
/// </summary> |
|
|
/// </summary> |
|
|
public void StartServer() |
|
|
public void StartServer() |
|
|
{ |
|
|
{ |
|
|
|
|
|
string path = System.Configuration.ConfigurationManager.AppSettings["StartServer"].ToString(); |
|
|
|
|
|
string processName = ""; |
|
|
|
|
|
|
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
string path = System.Configuration.ConfigurationManager.AppSettings["StartServer"].ToString(); |
|
|
|
|
|
if (System.IO.File.Exists(path)) |
|
|
if (System.IO.File.Exists(path)) |
|
|
{ |
|
|
{ |
|
|
Process.Start(path); |
|
|
|
|
|
|
|
|
processName = System.IO.Path.GetFileNameWithoutExtension(path); |
|
|
|
|
|
if (!IsProcess(processName)) |
|
|
|
|
|
{ |
|
|
|
|
|
Process.Start(path); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ThreadManage.GetInstance().StartLong(new Action(() => |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
if (!IsProcess(processName)) |
|
|
|
|
|
{ |
|
|
|
|
|
Process.Start(path); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
MessageLog.GetInstance.ShowEx($"{Name}:线程服务异常,原因:{ex.Message}"); |
|
|
|
|
|
} |
|
|
|
|
|
Thread.Sleep(3000); |
|
|
|
|
|
}), $"{Name},进程监控"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
catch (Exception ex) |
|
|
catch (Exception ex) |
|
@@ -181,6 +205,46 @@ namespace BPASmartClient.ScreenLib |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool IsProcess(string procName) |
|
|
|
|
|
{ |
|
|
|
|
|
bool isProcess = false; |
|
|
|
|
|
Process[] ps = Process.GetProcessesByName(procName); |
|
|
|
|
|
if (ps.Length > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
isProcess=true; |
|
|
|
|
|
} |
|
|
|
|
|
return isProcess; |
|
|
|
|
|
} |
|
|
|
|
|
/// <summary> |
|
|
|
|
|
/// 关闭进程 |
|
|
|
|
|
/// </summary> |
|
|
|
|
|
/// <param name="procName"></param> |
|
|
|
|
|
/// <returns></returns> |
|
|
|
|
|
public bool CloseProc(string procName) |
|
|
|
|
|
{ |
|
|
|
|
|
bool result = false; |
|
|
|
|
|
ArrayList procList = new ArrayList(); |
|
|
|
|
|
string tempName; |
|
|
|
|
|
int begpos; |
|
|
|
|
|
int endpos; |
|
|
|
|
|
foreach (Process thisProc in Process.GetProcesses()) |
|
|
|
|
|
{ |
|
|
|
|
|
tempName = thisProc.ToString(); |
|
|
|
|
|
begpos = tempName.IndexOf("(") + 1; |
|
|
|
|
|
endpos = tempName.IndexOf(")"); |
|
|
|
|
|
tempName = tempName[begpos..endpos]; |
|
|
|
|
|
procList.Add(tempName); |
|
|
|
|
|
if (tempName == procName) |
|
|
|
|
|
{ |
|
|
|
|
|
if (!thisProc.CloseMainWindow()) |
|
|
|
|
|
// 当发送关闭窗口命令无效时强行结束进程 |
|
|
|
|
|
thisProc.Kill(); |
|
|
|
|
|
result = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
/// <summary> |
|
|
/// <summary> |
|
|
/// 停止服务 |
|
|
/// 停止服务 |
|
|
/// </summary> |
|
|
/// </summary> |
|
|