Home > Net >  A single serial port operation, continuous send how to realize the last file sent before sending the
A single serial port operation, continuous send how to realize the last file sent before sending the

Time:09-19

A serial port to send: multiple sent files, how to realize the last time send the file before sending the task has been completed?

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 ();
}
  •  Tags:  
  • C#
  • Related