修复TCP温度数据接收问题:实现正确的持续读取机制
This commit is contained in:
@@ -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)
|
||||||
{
|
{
|
||||||
@@ -1305,12 +1305,8 @@ namespace JoyD.Windows.CS.Toprie
|
|||||||
localTcpClient = null;
|
localTcpClient = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
// while循环退出后的处理
|
||||||
{
|
|
||||||
// 短暂休眠避免CPU占用过高
|
|
||||||
Thread.Sleep(SHORT_SLEEP_MS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user