protected override void OnStart(string[] args) { try { base.OnStart(args); Configuration conf = Configuration.Deserialize(WorkingDir); Logger.IsDebugLevelEnabled = conf.Debug; switch (conf.Mode) { case RunningMode.SelfTesting: Instance = new SelfTestingMode.Instance(conf); break; case RunningMode.Api: Instance = new ApiMode.Instance(conf); break; default: throw new Exception(String.Format("Unsupported mode: {0}", conf.Mode)); } Instance.Start(); Logger.Info("Successfuly started service"); } catch (Exception ex) { Logger.Error("Could not start Worker: {0}", ex.ToString()); ExitCode = Misc.Constants.ErrorExceptionInService; Stop(); } }
protected override void OnStop() { base.OnStop(); if (Instance != null) { Instance.Join(); Instance = null; } Logger.Info("Service stopped successfully"); }