I have strange problem. I am trying to fast generate data (later, I will use input from I/O) and then draw them.
Because drawing is time consuming, I will add data to other array, to not block generating new ones.
public MainWindow() {
InitializeComponent();
DispatcherTimer adder = new DispatcherTimer {
Interval = new TimeSpan(0, 0, 0, 0, 1)
};
adder.Tick += AddData;
adder.Start();
DispatcherTimer refresher = new DispatcherTimer {
Interval = new TimeSpan(0, 0, 0, 0, 30)
};
refresher.Tick += RefreshScreen;
refresher.Start();
}
private void RefreshScreen(object sender, EventArgs e) {
Debug.WriteLine(queue.Count);
lock ( queue ) {
data.InsertRange(0, queue);
queue.Clear();
}
//ToDoLater
}
private void AddData(object sender, EventArgs e) {
queue.Enqueue(new TimedData());
}
class TimedData {
public int Value { get; private set; }
public DateTime Time { get; private set; }
public TimedData() {
Time = DateTime.Now;
Value = new Random().Next(0,200);
}
I expected queue count around 20-25 but i have only 2-3. That's really low. Where is problem? I tried use List instead of Queue, and to add all items to other list use Queue.Enqueue but with no significant improvement. What am I doing wrong?