StreamWriter.AutoFlush 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示每次调用StreamWriter后是否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
属性值
示例
下面的示例演示了使用该属性的 AutoFlush 语法。
// 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
注解
除非显式调用 Flush 或 Close调用流,否则刷新流不会刷新其基础编码器。
AutoFlush设置为true表示在每次写入操作后,数据将从缓冲区刷新到流,但不会刷新编码器状态。 这使编码器能够保持其状态(部分字符),以便它可以正确编码下一个字符块。 此方案影响 UTF8 和 UTF7,其中某些字符只能在编码器接收相邻字符或字符后进行编码。
如果 AutoFlush 设置为 false, StreamWriter 则会在编码器中执行有限数量的缓冲,同时在编码器中执行传入的编码。 你可以通过将设置设置为AutoFlushfalse(或者至少)在编写完时Close调用Flush(或至少StreamWriter)来获得更好的性能。
例如,当写入用户需要即时反馈的设备时,请设置为AutoFlushtrue该设备。
Console.Out 是以下情况之一: StreamWriter 用于写入以 Console 刷新其所有内部状态,但每次调用 StreamWriter.Write后编码器状态除外。
有关常见 I/O 任务的列表,请参阅 常见 I/O 任务。