求助 线程为什么会被自动销毁?
用一个线程循环去读一些信息,然后把符合条件的信息通过事件反馈出去,但是这个线程每次跑个两次就消失了,从任务管理器里看线程数少了一个,断点循环位置也进不去了
Task.Factory.StartNew(GetValue);
void GetValue()
{
while (true)
{
Thread.Sleep(200);
try
{
var status = tcpNet.ReadInt16("3").Content;
if (status == (short)1)
{
float weightValue = tcpNet.ReadFloat("0").Content;
if (weightValue == _lastValue)
{
return;
}
ReverseWeightEvent?.Invoke(weightValue);
_lastValue = weightValue;
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}