I had an interesting problem in my C # .Net 4.0 application using class SerialPortand ThreadPool.QueueUserWorkItemor or Tasks.
The problem only occurs when 2 or more serial ports are used simultaneously. Each serial port runs in its own thread, which I create in one of three ways:
new Thread(DoSerialCommX)ThreadPool.QueueUserWorkItem(DoSerialCommX)new Task(DoSerialCommX, TaskCreationOptions.LongRunning).Start()
To illustrate the problem, I created a method DoSerialCommXfor reading and writing to the serial port forever in a loop. It looks something like this: (I actually do not do this in my real program. This is just a fragment of my test program that isolates and illustrates the problem).
private void DoSerialCommX()
{
SerialPort port = new SerialPort("ComX", 9600);
port.Open();
while(true)
{
}
}
2 3, , - . 1, . , , , , Intel Atom. , , .
, , Task . , . TaskCreationOptions.LongRunning, , , , , .
, : Thread ? - Thread, -?
Edit:
, , , ThreadPool Tasks . . , . , Thread , ThreadPool Task - . , ?