Debug.Flush Yöntem

Tanım

Çıkış arabelleği temizler ve arabelleğe alınan verilerin koleksiyona yazmasına Listeners neden olur.

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 ()
Öznitelikler

Örnekler

Aşağıdaki örnek adlı myTextListenerbir TextWriterTraceListener oluşturur. myTextListeneradlı TestFile.txtbir FileStream dosyaya yazmak için adlı myFileStream bir kullanır. Örnek akışı oluşturur, varsa dosyayı açar veya yeni bir tane oluşturur, dosyaya bir satır metin yazar ve ardından çıkışı boşaltır ve kapatır.

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

Açıklamalar

Akışın boşaltılması, veya Closeöğesini açıkça çağırmadığınız Flush sürece temel alınan kodlayıcısını temizlemez. ayarı AutoFlushtrue , verilerin arabellekten akışa boşaltılacağı ancak kodlayıcı durumunun boşaltılmayacağı anlamına gelir. Bu, kodlayıcının durumunu (kısmi karakterler) tutarak sonraki karakter bloğunu doğru kodlamasını sağlar. Bu senaryo, belirli karakterlerin yalnızca kodlayıcı bitişik karakteri veya karakterleri aldıktan sonra kodlanabildiği UTF8 ve UTF7'yi etkiler.

Şunlara uygulanır

Ayrıca bkz.