BufferedStream.Close Método

Definição

Fecha o fluxo e libera todos os recursos (especialmente recursos de sistema, como soquetes e identificadores de arquivos) associados ao fluxo em buffer atual.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 ()

Exceções

Ocorreu um erro ao tentar fechar o fluxo.An error occurred while trying to close the stream.

Exemplos

Este exemplo de código faz parte de um exemplo maior fornecido para a BufferedStream classe.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();

Comentários

Todos os dados gravados anteriormente no buffer são copiados para a fonte de dados subjacente ou para o repositório antes de o fluxo em buffer ser fechado.Any data previously written to the buffer is copied to the underlying data source or repository before the buffered stream is closed. Portanto, não é necessário chamar antes de Flush() chamar Close.Therefore, it is not necessary to call Flush() before invoking Close. Após uma chamada para Close, todas as operações no fluxo em buffer podem gerar exceções.Following a call to Close, any operations on the buffered stream might raise exceptions.

A liberação do fluxo não liberará seu codificador subjacente, a menos que você chame explicitamente Flush() ou feche.Flushing the stream will not flush its underlying encoder unless you explicitly call Flush() or Close. Definir AutoFlush como true significa que os dados serão liberados do buffer para o fluxo, mas o estado do codificador não será liberado.Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. Isso permite que o codificador Mantenha seu estado (caracteres parciais) para que ele possa codificar corretamente o próximo bloco de caracteres.This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. Esse cenário afeta UTF8 e UTF7, em que determinados caracteres só podem ser codificados depois que o codificador recebe o caractere ou caracteres adjacentes.This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.

A tentativa de manipular um fluxo depois que ele foi fechado pode lançar um ObjectDisposedException .Attempting to manipulate a stream after it has been closed might throw an ObjectDisposedException.

Aplica-se a

Confira também