Trace.Flush Metoda

Definice

Vyprázdní výstupní vyrovnávací paměť a způsobí zápis dat do vyrovnávací paměti .Listeners

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

Příklady

Následující příklad vytvoří s TextWriterTraceListener názvem myTextListener. myTextListener používá volanou StreamWritermyOutputWriter k zápisu do souboru s názvem TestFile.txt. Příklad vytvoří soubor, datový proud a zapisovač textu, zapíše do souboru jeden řádek textu a pak vyprázdní a zavře výstup.

// Specify /DTRACE when compiling.

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

void main()
{
     #if defined(TRACE)
    // Create a file for output named TestFile.txt.
    FileStream^ myFileStream = 
        gcnew FileStream( "TestFile.txt", FileMode::Append );
   
    // Create a new text writer using the output stream 
    // and add it to the trace listeners.
    TextWriterTraceListener^ myTextListener = 
        gcnew TextWriterTraceListener( myFileStream );
    Trace::Listeners->Add( myTextListener );
   
    // Write output to the file.
    Trace::WriteLine( "Test output" );
   
    // Flush and close the output stream.
    Trace::Flush();
    Trace::Close();
    #endif
}
// Specify /d:TRACE when compiling.

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

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

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

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

Imports System.IO
Imports System.Diagnostics

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

End Class

Poznámky

Vyprázdnění datového proudu nevyprázdní jeho základní kodér, pokud explicitně nezavoláte Flush nebo Close. Nastavení AutoFlush na znamená true , že data budou vyprázdněna z vyrovnávací paměti do datového proudu, ale stav kodéru se nevyprázdní. To umožňuje kodéru zachovat svůj stav (částečné znaky), aby mohl správně zakódovat další blok znaků. Tento scénář má vliv na kódování UTF8 a UTF7, kde určité znaky lze zakódovat až poté, co kodér přijme sousední znak nebo znaky.

Platí pro

Viz také