Click here to Skip to main content
11,491,598 members (73,689 online)
Rate this: bad
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 4-Nov-11 0:10am

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 at 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
0 Sergey Alexandrovich Kryukov 521
1 Maciej Los 336
2 Andy Lanng 273
3 Sascha Lefèvre 245
4 OriginalGriff 155
0 Sergey Alexandrovich Kryukov 9,829
1 OriginalGriff 8,530
2 Sascha Lefèvre 3,579
3 Maciej Los 3,332
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 4 Nov 2011
Copyright © CodeProject, 1999-2015
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