NetworkStream.Close Method (Int32)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Closes the NetworkStream after waiting the specified time to allow data to be sent.

Namespace:   System.Net.Sockets
Assembly:  System (in System.dll)

public void Close(
	int timeout


Type: System.Int32

A 32-bit signed integer that specifies the number of milliseconds to wait to send any remaining data before closing.

Exception Condition

The timeout parameter is less than -1.

The Close method frees both unmanaged and managed resources associated with the NetworkStream. If the NetworkStream owns the underlying Socket, it is closed as well.

If a NetworkStream was associated with a TcpClient, the Close method will close the TCP connection, but not dispose of the associated TcpClient.

.NET Framework
Available since 2.0
Return to top