public void Cleanup() { if (broadcastServer != null) { broadcastServer.Close(); broadcastServer = null; } NetTrace.Stop(); AsyncTracker.Stop(); }
/// <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 (udpServer != null) { return; // Already started } // Global initialization NetTrace.Start(); Program.Config = new Config("LillTek.Datacenter.BroadcastServer"); Program.InstallPerfCounters(); // Service initialization this.serviceHost = serviceHost; SysLog.LogInformation("Broadcast Server v{0} Start", Helper.GetVersionString()); try { udpServer = new UdpBroadcastServer("LillTek.Datacenter.BroadcastServer", Program.PerfCounters, null); state = ServiceState.Running; } catch (Exception e) { if (udpServer != null) { udpServer.Close(); udpServer = null; } SysLog.LogException(e); throw; } } }
/// <summary> /// Stops the service immediately, terminating any user activity. /// </summary> public void Stop() { lock (syncLock) { if (state == ServiceState.Stopped) { return; } SysLog.LogInformation("Broadcast Server Stop"); SysLog.Flush(); base.Close(); state = ServiceState.Stopped; if (udpServer != null) { udpServer.Close(); udpServer = null; } Program.PerfCounters.Zero(); } }