/// <summary> /// Starts the service components. /// </summary> /// <param name="state">The state.</param> private void StartServiceComponents(object state) { //Debugger.Launch(); try { _miniDumpTraceListener = new MiniDumpTraceListener(); Trace.Listeners.Add(_miniDumpTraceListener); this.InitializeServiceComponents(); MyEventLog = CreateEventLog(ServiceName); this.Configuration = ConfigurationFactory.Create(this); this.WriteEventLog(EventLogEntryType.Information, 1073759243L, HostName, ServiceName); MyTrace.Write(TraceCategory.AsyncService, Mysoft.MAP2.Common.Trace.TraceLevel.Info, "正在启动异步服务: {0}", ServiceName); this.CreatePerformanceCounters(ServiceName); this.InitializeComponents(); this.StartComponents(); MyTrace.Write(TraceCategory.AsyncService, TraceLevel.Info, "异步服务完成启动: {0}", ServiceName); this.WriteEventLog(EventLogEntryType.Information, 1073759232L, HostName); } catch (System.Exception ex) { this.WriteEventLog(EventLogEntryType.Error, 3221242882L, HostName, ex.ToString()); MyTrace.Write(TraceCategory.AsyncService, TraceLevel.Error, "异步服务启动过程遭遇异常: {0} - {1}", ServiceName, ex); throw; } finally { this._startSequenceCompleted.Set(); } }
/// <summary> /// 在派生类中实现时,该方法于“服务控制管理器”(SCM) 将“停止”命令发送到服务时执行。 指定服务停止运行时采取的操作。 /// </summary> protected override void OnStop() { base.RequestAdditionalTime((int)System.TimeSpan.FromMinutes(5.0).TotalMilliseconds); this.WaitForStartupSequenceComplete(); MyTrace.Write(TraceCategory.AsyncService, TraceLevel.Info, "正在停止异步服务。"); this.StopComponents(); //SandboxHostManager.Shutdown(); if (MyEventLog != null) { this.WriteEventLog(EventLogEntryType.Information, 1073759233L, HostName); MyEventLog.Dispose(); MyEventLog = null; } MyTrace.Write(TraceCategory.AsyncService, TraceLevel.Info, "异步服务已经被停止: {0}", ServiceName); if (this._miniDumpTraceListener != null) { Trace.Listeners.Remove(this._miniDumpTraceListener); this._miniDumpTraceListener = null; } }