using System; using System.Collections.Generic; using System.Text; using System.ServiceProcess; // 先要添加引用 namespace ConsoleApplication16 { class Program { static void Main(string[] args) { ServiceController SC = new ServiceController("服务名"); SC.Stop(); SC.WaitForStatus(ServiceControllerStatus.Stopped); // 开始更新,替换dll SC.Start(); } } }
下载完毕且要执行更新时,启动一个外部进程(updater),然后调用service的stop方法
updater在启动后,检测service停止完毕后执行更新操作(就是替换service的相关文件)
updater更新完毕后启动service
更新结束
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess; // 先要添加引用 namespace ConsoleApplication16
{
class Program
{
static void Main(string[] args)
{
ServiceController SC = new ServiceController("服务名");
SC.Stop();
SC.WaitForStatus(ServiceControllerStatus.Stopped);
// 开始更新,替换dll
SC.Start();
}
}
}