using System.IO; using System.ServiceProcess; namespace FCS.Crawler { public partial class Service1 : ServiceBase { private JobManage manage = null; public Service1() { InitializeComponent(); manage = new JobManage(); } string filePath = $"{System.Windows.Forms.Application.StartupPath}\\XmlConfig\\11.txt"; protected override void OnStart(string[] args) { using (FileStream stream = new FileStream(filePath, FileMode.Append)) using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("开启服务!"); } manage.JobStart(); } protected override void OnStop() { using (FileStream stream = new FileStream(filePath, FileMode.Append)) using (StreamWriter writer = new StreamWriter(stream)) { writer.WriteLine("结束服务!"); } manage.JobStop(); } } }