此文记录的是一个应用程序重启的函数。
/*** 应用程序重启动 Austin Liu 刘恒辉 Project Manager and Software Designer E-Mail: [email protected] Blog: http://lzhdim.cnblogs.com Date: 2024-01-15 15:18:00 使用方法: AppUtil.RestartApplication(Application.ExecutablePath); 说明: 1、用于应用程序关闭后再启动操作,具体在使用时能够修改该代码; 2、比如应用的更新操作,将应用的EXE执行文件复制过来覆盖,然后重启; ***/ namespace Lzhdim.LPF.Utility { using System; using System.IO; using System.Diagnostics; using System.Windows.Forms; /// <summary> /// 应用工具类 /// </summary> public class AppUtil { /// <summary> /// 重启应用程序 /// </summary> public static void RestartApplication(string filePath) { Application.ExitThread(); // 启动应用程序 StartProcess(filePath); // 退出当前应用程序 Environment.Exit(0); } /// <summary> /// 启动应用程序 /// </summary> /// <param name="filename"></param> private static void StartProcess(string filename) { if (!File.Exists(filename)) { return; } if (!(Path.GetExtension(filename) == ".exe")) { return; } int index = filename.IndexOf('/'); if (index <= 0) { Process.Start(filename); } else { int length = filename.Length - index; string fileName = filename.Substring(0, index - 1); string arguments = filename.Substring(index, length); Process process = new Process { StartInfo = new ProcessStartInfo(fileName, arguments) }; process.StartInfo.UseShellExecute = false; process.Start(); } } } }
标签:return,C#,APP,System,应用程序,filename,using,重启 From: https://www.cnblogs.com/lzhdim/p/18324412