StreamWriter.AutoFlush Propriedade
Definição
Obtém ou define um valor que indica se o StreamWriter liberará o buffer para o fluxo subjacente após toda a chamada para Write(Char).Gets or sets a value indicating whether the StreamWriter will flush its buffer to the underlying stream after every call to Write(Char).
public:
virtual property bool AutoFlush { bool get(); void set(bool value); };
public virtual bool AutoFlush { get; set; }
member this.AutoFlush : bool with get, set
Public Overridable Property AutoFlush As Boolean
Valor da propriedade
true para forçar o StreamWriter a liberar o buffer; caso contrário, false.true to force StreamWriter to flush its buffer; otherwise, false.
Exemplos
O exemplo a seguir mostra a sintaxe para usar a AutoFlush propriedade.The following example shows the syntax for using the AutoFlush property.
// Gets or sets a value indicating whether the StreamWriter
// will flush its buffer to the underlying stream after every
// call to StreamWriter.Write.
sw->AutoFlush = true;
// Gets or sets a value indicating whether the StreamWriter
// will flush its buffer to the underlying stream after every
// call to StreamWriter.Write.
sw.AutoFlush = true;
' Gets or sets a value indicating whether the StreamWriter
' will flush its buffer to the underlying stream after every
' call to StreamWriter.Write.
Sw.AutoFlush = True
Comentários
A liberação do fluxo não liberará seu codificador subjacente, a menos que você chame explicitamente Flush ou Close .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 após cada operação de gravação, 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 after each write operation, 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.
Quando AutoFlush é definido como false , StreamWriter o fará uma quantidade limitada de buffer, tanto internamente quanto potencialmente no codificador, da codificação que você passou.When AutoFlush is set to false, StreamWriter will do a limited amount of buffering, both internally and potentially in the encoder from the encoding you passed in. Você pode obter melhor desempenho definindo AutoFlush como false , supondo que sempre chame Close (ou pelo menos) quando terminar de Flush escrever com um StreamWriter .You can get better performance by setting AutoFlush to false, assuming that you always call Close (or at least Flush) when you're done writing with a StreamWriter.
Por exemplo, defina AutoFlush como true quando você estiver gravando em um dispositivo no qual o usuário espera comentários imediatos.For example, set AutoFlush to true when you are writing to a device where the user expects immediate feedback. Console.Out é um destes casos: o StreamWriter usado internamente para gravação para Console liberar todo seu estado interno, exceto o estado do codificador após cada chamada para StreamWriter.Write .Console.Out is one of these cases: The StreamWriter used internally for writing to Console flushes all its internal state except the encoder state after every call to StreamWriter.Write.
Para obter uma lista de tarefas comuns de e/s, consulte tarefas comuns de e/s.For a list of common I/O tasks, see Common I/O Tasks.