void ObserveData(object sender, ElapsedEventArgs e) { //get partition counts, fill in combo box("lazy" update) var queryPartitionNumber = _hubDataReceiver.partitionNumber; if (queryPartitionNumber != Partitions.Count) { ObservableCollection <string> partitionIds = new ObservableCollection <string>(); for (int i = 0; i < queryPartitionNumber; i++) { partitionIds.Add(i.ToString()); } Partitions = partitionIds; } PartitionCount = Partitions.Count.ToString(); //get real time number to mark on the curve MessageRealTimeNumber = _hubDataReceiver.totalMessage; DeviceRealTimeNumber = _hubDataReceiver.totalDevice; //update properties for monitoring data var delaystringavg = _hubDataReceiver.deviceToHubDelayAvg; if (!string.IsNullOrEmpty(delaystringavg)) { try { DeviceToHubDelayAvg = delaystringavg.Substring(0, 11); } catch { DeviceToHubDelayAvg = "N/A"; } } var delaystring1min = _hubDataReceiver.deviceToHubDelayOneMin; if (!string.IsNullOrEmpty(delaystring1min)) { try { DeviceToHubDelay1Min = delaystring1min.Substring(0, 11); } catch { DeviceToHubDelay1Min = "N/A"; } } MessageContent = _hubDataReceiver.sampleContent; Throughput = (_hubDataReceiver.throughput).ToString() + " messages/minute"; HubThroughput = $"≈ {_hubDataReceiver.throughput * Partitions.Count} messages/minute"; FromDevice = _hubDataReceiver.sampleEventSender; var allsec = (int)_hubDataReceiver.runningTime.TotalSeconds; var datetimestring = DateTime.Now.ToString("HH:mm:ss"); CurrentTimeString = datetimestring; TimeStamp = $"Details(updated at {datetimestring})"; var elapsedstring = localwatch.Elapsed.ToString(); if (!string.IsNullOrEmpty(localwatch.Elapsed.ToString())) { try { LocalElapsedTime = elapsedstring.Substring(0, 11); } catch { LocalElapsedTime = "N/A"; } } //Update chart var currentTime = DateTime.Now; TimeStamps.Enqueue(currentTime); Labels.Add(currentTime.ToString("hh:mm:ss")); DeviceSeriesCollection[0].Values.Add(_deviceRealTimeNumber); MessageSeriesCollection[0].Values.Add(_messageRealTimeNumber); var earliestTime = currentTime; if (TimeStamps.Count != 0) { earliestTime = TimeStamps.Peek(); } //only collect recent 15min data. var timeDiff = currentTime.Subtract(earliestTime); if (timeDiff > new TimeSpan(0, 15, 1)) { Labels.RemoveAt(0); DeviceSeriesCollection[0].Values.RemoveAt(0); MessageSeriesCollection[0].Values.RemoveAt(0); TimeStamps.Dequeue(); } //check job status and stop refreshing. if (TaskTotalCount == TaskCompleteCount && TaskTotalCount != 0) { //stop working threads localwatch.Stop(); _hubDataReceiver.PauseReceive(); _refreshTaskTimer.Enabled = false; _refreshDataTimer.Enabled = false; if (!_deleteFlag) {//avoid "Conflict" CleanUpBatch(); CleanUpStorage(); _deleteFlag = true; } } }