I was initially using ObservableClass to store my CPU Usage information every second and move this information to a chart which was working but kept adding on to memory.
Got some advice and moved to opt for a Queue class to be able to remove the information after a certain period has passed. But unlike an observable class, I can't store 2 arguments.
Should I use both queue and observable class or queue class is enough for my issue.
Initial codes using Observable class
class CPUClass{
ObservableCollection<KeyValuePair<double, double>> cpuChartList = new ObservableCollection<KeyValuePair<double, double>>();
//this method is fired off every second
private void timerChange(){
counter += 1;
//cpuCurrent is the current cpu usage value every second
cpuChartList.Add(new KeyValuePair<double, double>(counter, cpuCurrent));
}
}
//On the MainWindow
cpulineChart.DataContext = CPUClass.cpuChartList;
Trying with Queue Class
class CPUClass{
Queue queueCPU = new Queue();
//to hold past 30 seconds cpu usage information at any point
private void timerChange(){
counter += 1;
if (queueCPU.Count > 30)
{
queueCPU.Dequeue();
counter -= 1;
}
queueCPU.Enqueue(cpuCurrent);//
}
}
//On the MainWindow
cpulineChart.DataContext = CPUClass.queueCPU;
As you can see when using Queue Class, I am not able to include my counter to keep track of seconds on the chart. This is new to me thus could have messed up the whole concept. Also pondering if the way I am adding and removing the counter for the Queue Class way is messy. Please advice. Thank you.