private void InitializeMode(XDTransportMode mode) { listener?.Dispose(); listener = client.Listeners.GetListenerForMode(mode); listener.MessageReceived += OnMessageReceived; if (statusCheckBox.Checked) { listener.RegisterChannel("Status"); } if (channel1Check.Checked) { listener.RegisterChannel("BinaryChannel1"); } if (channel2Check.Checked) { listener.RegisterChannel("BinaryChannel2"); } if (broadcast != null) { var message = $"{uniqueInstanceName} is changing mode to {mode}"; broadcast.SendToChannel("Status", message); } broadcast = client.Broadcasters.GetBroadcasterForMode(mode, propagateCheck.Checked); }
/// <summary> /// Broadcast a message that the service has stopped. /// </summary> protected override void OnStop() { broadcast.SendToChannel("Status", "Test Service has stopped"); cancelToken.Cancel(); cancelToken = null; listener.Dispose(); }
/// <summary> /// Implementation of IDisposable used to clean up the listener instance. /// </summary> public void Dispose() { if (propagateListener != null) { propagateListener.Dispose(); propagateListener = null; } }
public void Dispose(bool disposeManaged) { if (disposed) { return; } disposed = true; propagateListener?.Dispose(); if (!disposeManaged) { return; } nativeListener?.Dispose(); }
/// <summary> /// Implementation of IDisposable used to clean up the listener instance. /// </summary> public void Dispose(bool disposeManaged) { if (!disposed) { disposed = true; if (propagateListener != null) { propagateListener.Dispose(); } if (disposeManaged) { if (nativeListener != null) { nativeListener.Dispose(); } } } }
/// <summary> /// Initialize the broadcast and listener mode. /// </summary> /// <param name = "mode">The new mode.</param> private void InitializeMode(XDTransportMode mode) { if (listener != null) { // ensure we dispose any previous listeners, dispose should aways be // called on IDisposable objects when we are done with it to avoid leaks listener.Dispose(); } // creates an instance of the IXDListener object using the given implementation listener = client.Listeners.GetListenerForMode(mode); // attach the message handler listener.MessageReceived += OnMessageReceived; // register the channels we want to listen on if (statusCheckBox.Checked) { listener.RegisterChannel("Status"); } // register if checkbox is checked if (channel1Check.Checked) { listener.RegisterChannel("BinaryChannel1"); } // register if checkbox is checked if (channel2Check.Checked) { listener.RegisterChannel("BinaryChannel2"); } // if we already have a broadcast instance if (broadcast != null) { // send in plain text var message = string.Format("{0} is changing mode to {1}", uniqueInstanceName, mode); broadcast.SendToChannel("Status", message); } // create an instance of IXDBroadcast using the given mode broadcast = client.Broadcasters.GetBroadcasterForMode(mode, propagateCheck.Checked); }
/// <summary> /// Initialize the broadcast and listener mode. /// </summary> /// <param name="mode">The new mode.</param> public static void InitializeMode(XDTransportMode mode) { if (listener != null) { // ensure we dispose any previous listeners, dispose should aways be // called on IDisposable objects when we are done with it to avoid leaks listener.Dispose(); } listener = XDListener.CreateListener(mode); // attach the message handler listener.MessageReceived += OnMessageReceived; listener.RegisterChannel(CHANNEL_NAME); // create an instance of IXDBroadcast using the given mode, // note IXDBroadcast does not implement IDisposable broadcast = XDBroadcast.CreateBroadcast(mode, false); }
/// <summary> /// Initialize the broadcast and listener mode. /// </summary> /// <param name="mode">The new mode.</param> private void InitializeMode(XDTransportMode mode) { if (listener != null) { // ensure we dispose any previous listeners, dispose should aways be // called on IDisposable objects when we are done with it to avoid leaks listener.Dispose(); } // creates an instance of the IXDListener object using the given implementation listener = XDListener.CreateListener(mode); // attach the message handler listener.MessageReceived += new XDListener.XDMessageHandler(OnMessageReceived); // register the channels we want to listen on if (statusCheckBox.Checked) { listener.RegisterChannel("Status"); } // register if checkbox is checked if (channel1Check.Checked) { listener.RegisterChannel("Channel1"); } // register if checkbox is checked if (channel2Check.Checked) { listener.RegisterChannel("Channel2"); } // if we already have a broadcast instance if (broadcast != null) { broadcast.SendToChannel("Status", string.Format("{0} is changing mode to {1}", this.Handle, mode)); } // create an instance of IXDBroadcast using the given mode, // note IXDBroadcast does not implement IDisposable broadcast = XDBroadcast.CreateBroadcast(mode, propagateCheck.Checked); }
private void Exit() { listener?.UnRegisterChannel("AppackerProgress"); listener?.Dispose(); Application.Exit(); }