Click here to Skip to main content
15,173,299 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a Thread Function that reads data continuously from the Serial Port like this:
SerialPort _serialPort;
_serialPort = new SerialPort();
Thread ReceiveDataFromSerial = new Thread(ReadData)
byte[] buffer = new byte[20];
public void ReadData()


I need to read data from Six Serial ports using the same Thread Function.
How can I make Thread function that accept SerialPort as parameter and use that parameter to read from that particular Serial Port.


What I have tried:

Passing SerialPort Class member as parameter to a thread function
Updated 21-Mar-17 21:53pm

1 solution

I know that's been covered by Jon Skeet in here Multi-threading in .NET: Introduction and suggestions[^]

The general gist, I would have thought was something like this,

SerialPort _serialPort = ...
Thread thread = new Thread(() => ReadData(_serialPort, buffer));
public void ReadData(SerialPort _serialPort, byte[] buffer)
    _serialPort.Read(buffer, 0, 20);

although I think the passing/handling of the buffer may require more thought/attention than I've paid to it

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

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