/// <summary> /// Program entry point /// </summary> /// <param name="args"> /// Program arguments /// </param> static void Main(String[] args) { if (!Environment.UserInteractive) ServiceBase.Run(new WindowsService()); else { using (ServiceHost host = new ServiceHost()) { if (host.Startup()) { Console.Write("Press enter to shut down."); Console.ReadLine(); } } } }
/// <summary> /// Service stop override /// </summary> protected override void OnStop() { if (this.host != null) this.host.Dispose(); this.host = null; }
/// <summary> /// Service startup override /// </summary> /// <param name="args"> /// Service command line parameters /// </param> protected override void OnStart(String[] args) { this.host = new ServiceHost(); if (!this.host.Startup()) this.Stop(); }