private void Stop() { lock (syncRoot) { if (!this.running) { return; } this.running = false; } if (this.counterSenderSubsciption != null) { this.counterSenderSubsciption.Dispose(); this.counterSenderSubsciption = null; } if (this.counterSender != null) { this.counterSender.OnDisconnected -= new EventHandler(this.OnCounterSenderDisconnected); this.counterSender.OnError -= new EventHandler <UnhandledExceptionEventArgs>(this.OnCounterSenderError); this.counterSender.Dispose(); this.counterSender = null; } if (this.socketSender != null) { this.socketSender.Dispose(); this.socketSender = null; } }
public void Start() { lock (syncRoot) { if (this.running) { return; } this.running = true; } if (this.enabled) { try { if (this.protocol == ProtocolType.Pgm) { PgmSender sender; if (!NetworkInterface.GetIsNetworkAvailable()) { log.Warn("CounterPublisher could not started because no network connection is available."); return; } try { sender = new PgmSender(this.endPoint); if (this.sendInterface == null) { sender.Connect(); } else { sender.Connect(this.sendInterface.ToString()); } } catch (Exception exception) { log.WarnFormat("CounterPublisher could not started. To publish counter values the PGM protocol must be installed.\r\n: Error={0}", new object[] { exception }); throw; } this.socketSender = sender; } else if (this.protocol == ProtocolType.Udp) { UdpSender sender2 = new UdpSender(this.endPoint); sender2.Start(); this.socketSender = sender2; } else { this.socketSender = new HttpSender(this.address); } this.counterSender = new CounterSampleSender(this.senderId, this.sendInterval, this.socketSender, this.maxRequestsInQueue, -1, this.maxItemsPerRequest); this.counterSenderSubsciption = this.counterSender.SubscribeToChannel(this.counterPublisher.Channel); this.counterSender.OnDisconnected += new EventHandler(this.OnCounterSenderDisconnected); this.counterSender.OnError += new EventHandler <UnhandledExceptionEventArgs>(this.OnCounterSenderError); this.counterPublisher.Start(); this.counterSender.Start(); log.InfoFormat("CounterPublisher started on: {0}", new object[] { this.address }); } catch (SocketException exception2) { log.WarnFormat("CounterPublisher could not be created: ReturnCode={0}, Message={1}", new object[] { exception2.SocketErrorCode, exception2.Message }); throw; } } }