StreamWriter.AutoFlush 屬性

定義

取得或設定值,指出 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

屬性值

強制 StreamWriter 清除其緩衝區,則為 true,否則為 false

範例

下列範例顯示使用 屬性的 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;
' 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

備註

除非您明確呼叫 FlushClose,否則清除數據流不會排清其基礎編碼器。 設定 AutoFlushtrue 表示數據會在每次寫入作業之後從緩衝區排清到數據流,但不會排清編碼器狀態。 這可讓編碼器保持其狀態 (部分字元) ,以便正確地編碼下一個字元區塊。 此案例會影響UTF8和UTF7,其中某些字元只能在編碼器收到相鄰字元或字元之後進行編碼。

當 設定為 falseAutoFlushStreamWriter將會從您傳入的編碼,在內部和可能在編碼器中執行有限的緩衝處理。 您可以藉由將 設定AutoFlushfalse來取得更好的效能,假設您在完成撰寫 StreamWriter時一律呼叫 Close (或至少 Flush) 。

例如,當您寫入使用者預期立即意見反應的裝置時,請將 設定AutoFlushtrue為 。 Console.Out 是下列其中一種情況:用於 StreamWriter 寫入以 Console 排清其所有內部狀態,但每次呼叫 StreamWriter.Write之後的編碼器狀態除外。

如需一般 I/O 工作的清單,請參閱 一般 I/O 工作

適用於

另請參閱