修复TCP温度数据接收问题:实现正确的持续读取机制
This commit is contained in:
@@ -1256,10 +1256,10 @@ namespace JoyD.Windows.CS.Toprie
|
||||
_isReceivingTemperatureData = true;
|
||||
}
|
||||
|
||||
// 检查流是否有数据可读
|
||||
if (localStream.DataAvailable)
|
||||
// 持续读取温度数据流
|
||||
while (localTcpClient != null && localTcpClient.Connected && !isPaused)
|
||||
{
|
||||
// 读取数据
|
||||
// 使用阻塞读取方式,等待数据到达
|
||||
int bytesRead = localStream.Read(buffer, 0, buffer.Length);
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
@@ -1306,11 +1306,7 @@ namespace JoyD.Windows.CS.Toprie
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 短暂休眠避免CPU占用过高
|
||||
Thread.Sleep(SHORT_SLEEP_MS);
|
||||
}
|
||||
// while循环退出后的处理
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user