protected virtual void Dispose(bool disposing) { if (!Disposed) { if (disposing) { // TODO: dispose managed state (managed objects). } var cleanUpTimer = new Action(() => { UdpBroadcastTimer.Stop(); UdpBroadcastTimer.Tick -= UDPBroadcast; }); BlockingDispatcher.Run(cleanUpTimer); // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. _udpSocket.Dispose(); // TODO: set large fields to null. _instance = null; Disposed = true; } }
public void Suspend() { Util.LoggingService.LogInfo("suspending manager", Windows.Foundation.Diagnostics.LoggingLevel.Verbose); _mqttBroker?.Stop(); _udpMessaging?.Dispose(); _udpMessaging = null; }
public UDPMessaging() { if (_instance != null) { throw new Exception("Tried to create more than one UDPMessaging Class!"); } Task.Run(() => ((App)Application.Current).Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { UdpBroadcastTimer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(BroadcastIntervalSeconds) }; UdpBroadcastTimer.Tick += UDPBroadcast; UdpBroadcastTimer.Start(); })); _udpSocket.Bind(remoteEndPoint); //this event is used to give all the parameters to WSystem.net api var e = new SocketAsyncEventArgs(); var buffer = new byte[1024]; e.SetBuffer(buffer, 0, buffer.Length); e.RemoteEndPoint = remoteEndPoint; e.Completed += ReceiveFromCallback; //_udpSocket.ConnectAsync(new SocketAsyncEventArgs()); if (!_udpSocket.ReceiveFromAsync(e)) { ReceiveFromCallback(_udpSocket, e); } _instance = this; }
public void Suspend() { Debug.WriteLine("suspending manager"); _mqttBroker?.Stop(); _udpMessaging?.Dispose(); _udpMessaging = null; _datapointsSaver.Suspend(); }
public void Resume() { Util.LoggingService.LogInfo("resuming manager", Windows.Foundation.Diagnostics.LoggingLevel.Verbose); _mqttBroker?.Start(); if (_udpMessaging == null || _udpMessaging.Disposed) { _udpMessaging = new UDPMessaging(); } }
public void Resume() { Debug.WriteLine("resuming manager"); _mqttBroker?.Start(); if (_udpMessaging == null || _udpMessaging.Disposed) { _udpMessaging = new UDPMessaging(); } _datapointsSaver.Resume(); }
private bool disposedValue; // To detect redundant calls public LANManager() { lock (_lock) { if (_mqttBroker == null) { _mqttBroker = new MqttBroker(); _mqttBroker.Start(); _udpMessaging = new UDPMessaging(); _mqttBroker.MsgPublishReceived += MqttMessageRecieved; } else { throw new Exception("You should only instantiate this class once! "); } } }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // TODO: dispose managed state (managed objects). _udpMessaging?.Dispose(); } if (_mqttBroker != null) { _mqttBroker.MsgPublishReceived -= MqttMessageRecieved; _mqttBroker.Stop(); } _mqttBroker = null; _udpMessaging = null; // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. disposedValue = true; } }