Passing Parameters when initialising multiple threads

C

CaptainCaveman

Hi

I am setting up a simple app that will poll a device on the network.
This device has multiple ports which it uses to talk to some hardware. Each
port is assigned a port number from the network device as part of the
netowrk device, e.g. Network device has an IP address of 10.0.0.40, and
devices attached to the network device are assigned a port which is used to
reference them, e.g. Device on port 1 is referenced 10.0.0.40:1000 and
Device on port 4 is referenced 10.0.0.40:1003.

I want to set up a thread that will have the port number assigned, and
communications will happen with a single device. For example I want my first
thread to talk solely to Port 1 and it iwll have the IP address of the
network device, and the port passed as parameters.
That is fine, I cna manage that.

What I am struggling to work out is how to run a loop to start off all the
threads I need to. I want to pass as a parameter the Port number for each
thread.

I am creating my threads as below.....

readNetworkReportThread = new Thread(new
ThreadStart(this.ThreadReadFromNetwork));
readNetworkReportThread.IsBackground = true;
readNetworkReportThread.Start();
and I am run my threads like this
private void ThreadReadFromNetwork()
{
// reset events
m_EventNetStopThread.Reset();
m_EventNetThreadStopped.Reset();
//create the thread and start if running
ReadContinuousNetworkData ReadFromNetwork;
ReadFromNetwork = new ReadContinuousNetworkData(m_EventNetStopThread,
m_EventNetThreadStopped, this, IPAddress, PortNum);
ReadFromNetwork.Run();
}

How can I pass the Portnumber to the thread if I cant pass the portnumber to
the thread start function ThreadReadFromNetwork?

TIA

CC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top