C#/.NET基于Topshelf创建Windows服务的守护程序作为服务启动的客户端桌面程序不显示UI界面的问题分析和解决方案 (2)

修改ProcessHelper.cs为如下代码:

using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace TopshelfDemoService { /// <summary> /// 进程处理帮助类 /// </summary> internal class ProcessorHelper { /// <summary> /// 获取当前计算机所有的进程列表(集合) /// </summary> /// <returns></returns> public static List<Process> GetProcessList() { return GetProcesses().ToList(); } /// <summary> /// 获取当前计算机所有的进程列表(数组) /// </summary> /// <returns></returns> public static Process[] GetProcesses() { var processList = Process.GetProcesses(); return processList; } /// <summary> /// 判断指定的进程是否存在 /// </summary> /// <param></param> /// <returns></returns> public static bool IsProcessExists(string processName) { return Process.GetProcessesByName(processName).Length > 0; } /// <summary> /// 启动一个指定路径的应用程序 /// </summary> /// <param></param> /// <param></param> public static void RunProcess(string applicationPath, string args = "") { try { ProcessExtensions.StartProcessAsCurrentUser(applicationPath, args); } catch (Exception e) { var psi = new ProcessStartInfo { FileName = applicationPath, WindowStyle = ProcessWindowStyle.Normal, Arguments = args }; Process.Start(psi); } } } }

其中更改了方法RunProcess()的调用方式。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zysjwp.html