using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; namespace StartReportService { public partial class Service1 : ServiceBase { private System.Timers.Timer timer1 = new System.Timers.Timer(); public Service1() { timer1.Interval = 1800000; timer1.Elapsed += Timer1_Elapsed; InitializeComponent(); } private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { timer1.Stop(); try { ServiceController serviceController = new ServiceController("ReportServer"); if (serviceController.Status != ServiceControllerStatus.Running && serviceController.Status != ServiceControllerStatus.StartPending && serviceController.Status != ServiceControllerStatus.ContinuePending) { serviceController.Start(); } } catch (System.Exception err) { } timer1.Start(); } protected override void OnStart(string[] args) { timer1.Start(); } protected override void OnStop() { timer1.Stop(); } } }