修复TCP温度数据接收问题:实现正确的持续读取机制

This commit is contained in:
zqm
2025-11-03 09:04:24 +08:00
parent 2ba884311b
commit 62e1a8846c

View File

@@ -1256,10 +1256,10 @@ namespace JoyD.Windows.CS.Toprie
_isReceivingTemperatureData = true; _isReceivingTemperatureData = true;
} }
// 检查流是否有数据可读 // 持续读取温度数据流
if (localStream.DataAvailable) while (localTcpClient != null && localTcpClient.Connected && !isPaused)
{ {
// 读取数据 // 使用阻塞读取方式,等待数据到达
int bytesRead = localStream.Read(buffer, 0, buffer.Length); int bytesRead = localStream.Read(buffer, 0, buffer.Length);
if (bytesRead > 0) if (bytesRead > 0)
{ {
@@ -1306,11 +1306,7 @@ namespace JoyD.Windows.CS.Toprie
continue; continue;
} }
} }
else // while循环退出后的处理
{
// 短暂休眠避免CPU占用过高
Thread.Sleep(SHORT_SLEEP_MS);
}
} }
catch (Exception ex) catch (Exception ex)
{ {