Click here to Skip to main content
12,998,483 members (128,555 online)
Rate this:
Please Sign up or sign in to vote.
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 3-Nov-11 23:10pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
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

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 4 Nov 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100