Debug.Close Metoda

Definicja

Opróżnia bufor wyjściowy, a następnie wywołuje metodę Close dla każdego z elementów Listeners.

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

Przykłady

W poniższym przykładzie zostanie utworzona nazwana TextWriterTraceListener.myTextListener myTextListener używa wywołania StreamWritermyOutputWriter do zapisu w pliku o nazwie TestFile.txt. W przykładzie tworzony jest plik, strumień i składnik zapisywania tekstu, zapisuje jeden wiersz tekstu w pliku, a następnie opróżnia i zamyka dane wyjściowe.

// 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

Uwagi

Użyj tej metody, gdy dane wyjściowe trafią do pliku, na przykład do pliku TextWriterTraceListener.

Opróżnienie strumienia nie spowoduje opróżnienia jego podstawowego kodera, chyba że jawnie wywołasz Flush metodę lub Close. Ustawienie AutoFlush oznacza true , że dane zostaną opróżnione z buforu do strumienia, ale stan kodera nie zostanie opróżniony. Dzięki temu koder może zachować swój stan (częściowe znaki), aby można było poprawnie zakodować następny blok znaków. Ten scenariusz ma wpływ na utF8 i UTF7, gdzie niektóre znaki mogą być kodowane tylko po otrzymaniu sąsiadującego znaku lub znaków.

Dotyczy

Zobacz też