A serial port receives: multiple will send the file corresponding to a serial port feedback response, how to read sequentially serial port?
CodePudding user response:
Queue of the serial port to send and receive operation, can use SemaphoreSlim, I also am recently used, give you a simple example, (PS: you give you too little)
The static SemaphoreSlim _semaphore=new SemaphoreSlim (1);//the number here is the resources of the queue number
Private void button_Click (object sender, EventArgs e)
{
For (int I=1; i <6; I++)//
{
Thread _thread=new Thread (()=& gt;//here as your file
{
GetTest ();
});
_thread. Name="thread" + I;
_thread. Start ();
}
}
Public void getTest ()
{
_semaphore. Wait ();
//here is the upload or receive operation
_semaphore. Release ();
}