blah blah blah is here! blah blah » Close

up0down
link

Hi All,

Quick Yes or No question does the Serial Port class generate seperate threads if you are using mulltiple instances of it or does it all exist in the same thread?

Glenn

last answered one year ago

2 answers

up0down
link

Hi,

I have a read of Joseph Albrahari's PDF book on threads "Threading in C#" that has answered the question which caused this question. I think Serial Ports all exist on the same thread. still if some one could confirm...
Glenn

up0down
link

Well, I don't know for sure but I'd have thought that each instance of the SerialPort class would need a separate thread on which to raise its events. If it were otherwise, then you wouldn't be able to receive data 'concurrently' from two separate ports and, in any case, there's no obvious mechanism whereby separate instances could be 'aware' of each other.

It's possible that all three events (DataReceived, PinChanged and ErrorReceived) use the same secondary thread for a given instance because it says in the MSDN docs that only one event handler can execute at a time. Could this be what the Albahari book is saying?

GlennP
329

Well you have come back with what I originally thought. I think I am in midst of some political fighting, along the lines of "That software that was sent to Doesn't work the hardware needed modding etc. Our software guy has to sit down and rewrite it using strings"<- I think threads were meant as it makes no sense otherwise. I get a copy of my code that has been hacked to solve another problem. I was going through the motions of trying to work out why a thread was created that did nothing, here endeth the rant! Glenn

Feedback