Click here to Skip to main content
15,892,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi experts,

the SerialPort seems to be quite popular these days on CP. I'm developing an application that uses it, too.

Data from an external device is received via the DataReceived event. MSDN[^] tells us that the event handler runs on a secondary thread.

Does that mean that each event starts a new event handling thread or is there exactly one event handling thread (separated from the UI thread) that handles the DataReceived events one after another?

Same question in other words: Is there a risk that a long lasting DataReceived event handling routine causes SerialPort to miss data?
Posted

1 solution

Serial Ports are buffered, both in the hardware and within Windows so there is little risk of overrun, unless you are taking a stupidly long time in the handler - remember that event handlers are not interrupts, so the hardware can continue buffering data perfectly happily while you work with it.

Having said that, you should still keep event handlers as short as possible as a general rule, and that doesn't change when you use a serial port.
 
Share this answer
 
Comments
lukeer 4-Nov-11 8:29am    
Thanks, I'll let potentially long-lasting operations run in separate threads.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900