The whole idea to read something in the timer event is bad. More exactly, it's not working. The ports is read not by any moments of time, but then data is written from the other end of your RS-232 cable. When you try to read data, and the data is not put in the buffer, it's fine. This call behaves like a
blocking call, so your reading threads gets to the
wait state, until it get awaken, by getting data in a buffer, or some other reason (timeout, thread abortion/termination).
Therefore, do this: put all your serial communication in a separate thread, along with all the logic responsible for the communication. For notification of the event on the UI, use the UI thread invocation mechanism explained in my past answers referenced below.w Window">^].
The idea is: you cannot call anything related to UI from non-UI thread. Instead, you need to use the method
Invoke
or
BeginInvoke
of
System.Windows.Threading.Dispatcher
(for both Forms or WPF) or
System.Windows.Forms.Control
(Forms only).
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
—SA