Using .NET 4.0 on Windows 8.1 (x64).
I need to detect message frames in a "semi-real-time fashion", i.e. the only way to detect message frames are by detecting a mandatory minimum silent interval between messages.
The real need is to detect silent intervals of down to 2 ms, however for most practical purposes an interval of e.g. 50 ms is sufficient.
I found two ways of achieving this by using Serialport, briefly described as:
1: By using ReadByte() and handling the port's TimeoutException.
2: By disabling port timeout (Serialport.InfiniteTimeout) and detecting the silence by a System.Threading.Timer callback.
For both methods I have to turn off driver's FIFO buffer, if not, timing problems will occur.
Both methods work just fine (it seems like the Exception method has more accurate timing though, does it use a better timer internally ?), cpu load is pretty much the same and the Exception method makes it slightly easier (only one thread involved).
The Exception method throws an Exception (of course) which is reported in the output window ("A first chance exception of type 'System.TimeoutException' occurred in System.dll"), a little bit annoying during debugging (can be disabled, but that would disable other exceptions from being reported in the output window as well, or perhaps it is possible to disable only this one programmatically ?).
Anyone has some opinion which is "best" (or perhaps some other reading mechanism) ?
I ask because there are numerous of statements out there saying that exceptions should only be used by handling errors due to non-controllable environment, not as a part of a "normal" execution flow, perhaps something important I ignore in my code which hits me back later ?
(Indeed I am considering this frame detection as a "normal" execution flow.)