System.IO.Ports.SerialPort.Close Method

Closes the port connection, sets the SerialPort.IsOpen property to false, and disposes of the internal System.IO.Stream object.

Syntax

public void Close ()

Remarks

Calling this method closes the System.IO.Ports.SerialPort object and clears both the receive and transmit buffers. This method calls the System.ComponentModel.Component.Dispose method, which invokes the protected SerialPort.Dispose(bool) method with the disposing parameter set to true.

The best practice for any application is to wait for some amount of time after calling the SerialPort.Close method before attempting to call the SerialPort.Open method, as the port may not be closed instantly.

Requirements

Namespace: System.IO.Ports
Assembly: System (in System.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0