[英]C# error when a loop is inside a timer1_Tick function
我不太了解线程。 当我将这个while循环放入timer100_Tick函数(间隔为100)时,我只是在UI中有一个timer1:
count = port.BytesToRead;
while (count > 0)
{
// get the new byte:
char inchar = (char)port.ReadChar();
// add it to the inputstring:
inputString += inchar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inchar == '\n')
{
stringComplete = true;
}
}
程序停止响应任何UI输入。我知道问题出在线程和UI线程上,但是我对线程的了解很少。
那么解决这个问题的办法是什么
您没有递减count
变量,所以while(count > 0)
永不退出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.