Debug.Flush メソッド

定義

出力バッファーをフラッシュし、バッファー内のデータを Listeners コレクションに書き込みます。

public:
 static void Flush();
[System.Diagnostics.Conditional("DEBUG")]
public static void Flush();
[<System.Diagnostics.Conditional("DEBUG")>]
static member Flush : unit -> unit
Public Shared Sub Flush ()
属性

次の例では、TextWriterTraceListenerという名前のmyTextListenerを作成します。 myTextListenerでは、FileStream と呼ばれるmyFileStreamを使用して、TestFile.txt という名前のファイルに書き込みます。 この例では、ストリームを作成し、存在する場合はファイルを開くか、新しいストリームを作成し、1 行のテキストをファイルに書き込んでから、出力をフラッシュして閉じます。

// Specify /d:DEBUG when compiling.

using System;
using System.IO;
using System.Diagnostics;

class Test
{
    static void Main()
    {
        // Create a new stream object for an output file named TestFile.txt.
        using (FileStream myFileStream =
            new FileStream("TestFile.txt", FileMode.Append))
        {
            // Add the stream object to the trace listeners.
            TextWriterTraceListener myTextListener =
                new TextWriterTraceListener(myFileStream);
            Debug.Listeners.Add(myTextListener);

            // Write output to the file.
            Debug.WriteLine("Test output");

            // Flush and close the output stream.
            Debug.Flush();
            Debug.Close();
        }
    }
}
' Specify /d:DEBUG=True when compiling.

Imports System.IO
Imports System.Diagnostics

Class Test
    
    Shared Sub Main()
    
        ' Create a new stream object for an output file named TestFile.txt.
        Using myFileStream As New FileStream("TestFile.txt", FileMode.Append)
        
            ' Add the stream object to the trace listeners. 
            Dim myTextListener As New TextWriterTraceListener(myFileStream)
            Debug.Listeners.Add(myTextListener)
            
            ' Write output to the file.
            Debug.WriteLine("Test output")
            
            ' Flush and close the output stream.
            Debug.Flush()
            Debug.Close()
        
        End Using
        
    End Sub

End Class

注釈

明示的に Flush または Closeを呼び出さない限り、ストリームをフラッシュしても、基になるエンコーダーはフラッシュされません。 AutoFlushtrue に設定すると、データはバッファーからストリームにフラッシュされますが、エンコーダーの状態はフラッシュされません。 これにより、エンコーダーは状態 (部分的な文字) を保持して、次の文字ブロックを正しくエンコードできます。 このシナリオは UTF8 と UTF7 に影響を与え、エンコーダーが隣接する文字を受信した後でのみ特定の文字をエンコードできます。

適用対象

こちらもご覧ください