public void Stop() { if (_isStopped) { return; } _logger?.Info("DataCollector stopping..."); List <UnitedSensorValue> allData = new List <UnitedSensorValue>(); if (_dataQueue != null) { //allData.AddRange(_dataQueue.GetAllCollectedData()); allData.AddRange(_dataQueue.GetCollectedData()); _dataQueue.Stop(); } Thread.Sleep(TimeSpan.FromSeconds(1)); foreach (var pair in _nameToSensor) { if (pair.Value.HasLastValue) { allData.Add(pair.Value.GetLastValueNew()); } } foreach (var pair in _nameToSensor) { pair.Value.Dispose(); } if (allData.Any()) { //SendData(allData); SendMonitoringData(allData); } _client?.Dispose(); _isStopped = true; _logger?.Info("DataCollector successfully stopped."); }