我有这个代码语句并将它运行到一个计时器中,它的间隔是 50 毫秒。工作后thread1
,我的链表(数据)等于 Read_Data3。然后我检查这个条件if (data.ElementAt(0) == Convert.ToByte('$'))
。但是它给出了一个错误,说“值不能为空”。我检查了数组和链表不为空。这个错误的原因是什么?任何想法?
thread1 = new Thread(delegate()
{
Read_Data2 = Read_Data1;
lastCount = count;
division = lastCount / 18;
remaning = (lastCount - 18 * division);
Read_Data3 = new byte[lastCount - remaning];
for (int i = 0; i < lastCount - remaning; i++)
{
Read_Data3[i] = Read_Data2[i];
}
if (remaning > 0)
{
Read_Data4 = new byte[remaning];
for (int i = 0; i < remaning; i++)
{
Read_Data4[i] = Read_Data2[lastCount - remaning + i];
}
}
count = remaning;
if (lastCount - remaning > 17)
data = new LinkedList<byte>(Read_Data3);
});
thread1.Start();
if (data.ElementAt(0) == Convert.ToByte('$'))
{
for (int i = 0; i < (lastCount - remaning) / 18; i++)
{
//time = new XDate(DateTime.Now);
if (data.ElementAt(0) == Convert.ToByte('$'))
{
data.Remove(data.ElementAt(0));
for (int x = 0; x < 16; x++)
{
listAuido.Add(time, data.ElementAt(0));
data.Remove(data.ElementAt(0));
}
listPulse.Add(time, data.ElementAt(0));
data.Remove(data.ElementAt(0));
}
zgcMasterPane.AxisChange();
}
if (remaning > 0)
{
data2 = new LinkedList<byte>(Read_Data4);
data2.Remove(data2.ElementAt(0));
time = new XDate(DateTime.Now);
for (int i = 0; i < remaning - 2; i++)
{
listAuido.Add(time, data2.ElementAt(0));
data2.Remove(data2.ElementAt(0));
}
}
}