title: C# error when a loop is inside a timer1_Tick function
body: <p>I don't know much about threading. I simply have a timer1 in the UI, when I put this while loop inside the timer1_Tick function which is 100 intervals:</p>
  
  <pre><code>count = port.BytesToRead;
  while (count &gt; 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;
    }
  }
  </code></pre>
  
  <p>The program stop responding for any UI input.I know that the problem is about threading and UI thread but I have few knowledge in threading as I said. <br> So what is the solution for such a problem</p>