/// <summary> /// Stops the service immediately, terminating any user activity. /// </summary> public void Stop() { lock (syncLock) { if (state == ServiceState.Stopped) { return; } SysLog.LogInformation("Config Service Stop"); SysLog.Flush(); base.Close(); state = ServiceState.Stopped; if (router != null) { handler.Stop(); handler = null; router.Stop(); router = null; } } }
/// <summary> /// Starts the service, associating it with an <see cref="IServiceHost" /> instance. /// </summary> /// <param name="serviceHost">The service user interface.</param> /// <param name="args">Command line arguments.</param> public void Start(IServiceHost serviceHost, string[] args) { lock (syncLock) { if (router != null) { return; // Already started } // Global initialization NetTrace.Start(); Program.Config = new Config(ConfigServiceHandler.ConfigPrefix); Program.PerfCounters = null; // $todo(jeff.lill): new PerfCounterSet(true,Const.ConfigServicePerf,Const.ConfigServiceName); // Service initialization this.serviceHost = serviceHost; SysLog.LogInformation("Config Service v{0} Start", Helper.GetVersionString()); try { router = new LeafRouter(); router.Start(); handler = new ConfigServiceHandler(); handler.Start(router, null, null, null); state = ServiceState.Running; } catch (Exception e) { if (handler != null) { handler.Stop(); handler = null; } if (router != null) { router.Stop(); router = null; } SysLog.LogException(e); throw; } } }