public async Task<double[]> Meas_Back(int Wait_Time)
{
double[] ret = new double[ScanCount];
DateTime waitTime = DateTime.Now. AddMilliseconds (Wait_Time);
while (DateTime.Now < waitTime & serialPort. BytesToRead < 2)
{ await Task. Delay(100); }
string[] buffer = Read("\n").Split(',');
for (int i = 0; i < buffer.Count(); i++)
{
double. TryParse(Regex. Replace(buffer[i].Split(',')[0], @"[^\d. Ee+-]", ""), out ret[i]);
}
serial Port. DiscardInBuffer();
return ret;
}
這是我的程式碼,用翻譯轉貼到手機的,我想要問為什麼我用逐行執行執行到await 後...就消失了,整個程式卡住,想問一下我要如何排除這個問題與為什麼會發生
會不會是DateTime.Now < waitTime
及 serialPort. BytesToRead < 2
條件永遠都成立,所以導致迴圈跳不出去呢?
我猜是因為您呼叫Meas_Back時沒有await,可以改成下面這樣試試看
await Meas_Back(Wait_Time);