17 data come in consecutively through TCP communication. I'm trying to add data to the model bound to the datagrid, but when I add it, it's bound to the UI, so I'm using Device.BeginInvokeOnMainThread to add it. However, it seems that the ui thread works after receiving all 17 data because it is piled up in the thread pool and cannot be added sequentially. How do I add data sequentially?
await Task.Run(() =>
{
Thread.CurrentThread.Priority = ThreadPriority.Highest;
QuantitationMeasureData data = new QuantitationMeasureData()
{
GroupNumber = m_nCurRow,
GroupName = "Group" + m_nCurRow,
SampleName = "Sample" + m_nCurRow,
Cell = e.Cell.ToString(),
Time = GlobalParam.Time.Now,
Wave = this.m_Model.STCInfo.Wavelength,
Base1 = this.m_Model.STCInfo.BaseWave1,
Base2 = this.m_Model.STCInfo.BaseWave2,
Trans = e.Trans,
ABS = dRetABS,
Conc = dRetConc,
Factor = this.m_Model.Factor,
AVG = dRetABS,
STD = dRetConc,
};
Device.BeginInvokeOnMainThread(() =>
{
this.m_Model.MeasureDataCollection.Add(data);
this.xDataGrid.RefreshData();
});
});
I think there is no timing to run the ui thread because the data from 1 to 17 comes in quickly.
There's a priority queue for UI work. Code updates such as Invoke have higher priority than redraws, so as long as there's a code update to do, the UI won't redraw itself. This is why you're seeing multiple updates simultaneously.
If you want to see the updates one at a time, you'll need to delay them. 100ms is a good rule of thumb for "really fast but slow enough to be seen". You can either delay adding them to the UI or use a UI animation.