12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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 StartService
- {
- 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("EMIS.Service");
- 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();
- }
- }
- }
|