Click here to Skip to main content
Rate this: bad
good
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
lukeer15.1K

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
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 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,260


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 4 Nov 2011
Copyright © CodeProject, 1999-2014
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