【发布时间】:2017-08-24 10:26:36
【问题描述】:
我对线程了解不多。我只是在 UI 中有一个 timer1,当我将这个 while 循环放在 timer1_Tick 函数中时,它是 100 个间隔:
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 线程上,但正如我所说,我对线程的了解很少。
那么这样的问题有什么解决办法
【问题讨论】:
-
你的定时器启用了吗?
-
@imsome1 是的
-
它是否响应来自 UI 的第一个请求?
标签: c# multithreading timer