Why is Thread.Sleep () before SerialPort.Open and Close?

I notice code examples that I read after closing and opening SerialPort, where people added Thread.Sleep (1000) to SerialPort.Open () and Close (). As below:

Thread.Sleep(1000);
serialPort1.Open();
/* some code */
Thread.Sleep(1000);
serialPort1.Close();

I can’t find anything. Why do people block the serial port using Thread.Sleep before it gets Open or Close? Is this for some temporary purpose? Should I put Thread.Sleep whenever I read or write to the Serial Port?

+5
source share
3 answers

, SerialPort , ( WaitCommEvent Windows API) (, ) , , DataReceived, .

, Close() , .

Close, , SerialPort , .

MSDN SerialPort.Close:

Close Open , .

, , , , - -.

/, :

, SerialPort .NET BCL - API Win32, , Microsoft .

.

+9

SerialPort . Close, Open, .

.

+3

Serial I/O #, , . ( , )

.

+1

All Articles