Debug.Close Metoda

Definicja

Opróżnia bufor wyjściowy, a następnie wywołuje metodę Close na każdym 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 TextWriterTraceListenermyTextListener. myTextListener używa wywołania StreamWritermyOutputWriter do zapisu w pliku o nazwie TestFile.txt. Przykład tworzy plik, strumień i moduł zapisywania tekstu, zapisuje jeden wiersz tekstu w pliku, a następnie opróżnia i zamyka dane wyjściowe.

// Specify /DDEBUG when compiling.

#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Diagnostics;

void main()
{
     #if defined(DEBUG)
    // Create a new stream object for an output file named TestFile.txt.
    FileStream^ myFileStream = 
        gcnew FileStream( "TestFile.txt", FileMode::Append );
   
    // Add the stream object to the trace listeners.
    TextWriterTraceListener^ myTextListener = 
        gcnew 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();
    #endif
}
// 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 przechodzą do pliku, takiego jak TextWriterTraceListener.

Opróżnienie strumienia nie spowoduje opróżnienia jego kodera bazowego, chyba że jawnie wywołasz Flush 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ć 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ć zakodowane tylko po otrzymaniu sąsiadującego znaku lub znaków.

Dotyczy

Zobacz też