I define ConcurrentQueue as a ViewModel class field in my WPF MVVM application:
private ConcurrentQueue<AGC_DataRecordToSave> _agcAbsoluteDataRecordsToSaveBuf = new ConcurrentQueue<AGC_DataRecordToSave>();
Below is AGC_DataRecordToSave definition:
/// <summary>
/// Structure of record to write in CSV-file.
/// </summary>
public class AGC_DataRecordToSave
{
#region Public Fields
/// <summary>
/// Date
/// </summary>
public DateTime Data;
/// <summary>
/// Time
/// </summary>
public TimeSpan Time;
/// <summary>
/// Measuring Ultrasonic Beam.
/// </summary>
public int MeasuringBeam;
/// <summary>
/// Direction.
/// </summary>
public string Direction;
/// <summary>
/// Value from outer device.
/// </summary>
public double Value;
#endregion
}
Then in System.Windows.Threading.DispatcherTimer tick handler (in the same class) I do the following:
AGC_DataRecordToSave record = new AGC_DataRecordToSave();
record.Data = new DateTime(this._currentDate.Date.Ticks);
record.Time = this._currentDate.TimeOfDay;
record.MeasuringBeam = 1;
record.Direction = "P1AB";
record.Value = automaticGainControl;
this._agcAbsoluteDataRecordsToSaveBuf.Enqueue(record);
And _agcAbsoluteDataRecordsToSaveBuf remains empty (Count == 0). So ConcurrentQueue.Enqueue method doesn't add the value to the collection. AGC_DataRecordToSave record object is created and filled with the data successfully. I check it in debuger. Why the value is not added to collection? Why this situation has plase? Please help to solve this problem.