BufferedStream.Close Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Closes the stream and releases any resources (especially system resources such as sockets and file handles) associated with the current buffered stream.
public:
override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()
Exceptions
An error occurred while trying to close the stream.
Examples
This code example is part of a larger example provided for the BufferedStream class.
' When bufStream is closed, netStream is in turn
' closed, which in turn shuts down the connection
' and closes clientSocket.
Console.WriteLine(vbCrLf & "Shutting down the connection.")
bufStream.Close()
// When bufStream is closed, netStream is in turn
// closed, which in turn shuts down the connection
// and closes clientSocket.
Console.WriteLine("\nShutting down the connection.");
bufStream.Close();
// When bufStream is closed, netStream is in turn closed,
// which in turn shuts down the connection and closes
// clientSocket.
Console::WriteLine( "\nShutting down connection." );
bufStream->Close();
Remarks
Any data previously written to the buffer is copied to the underlying data source or repository before the buffered stream is closed. Therefore, it is not necessary to call Flush() before invoking Close. Following a call to Close, any operations on the buffered stream might raise exceptions.
Flushing the stream will not flush its underlying encoder unless you explicitly call Flush() or Close. Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.
Attempting to manipulate a stream after it has been closed might throw an ObjectDisposedException.