Debug.Flush Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Rensar utdatabufferten och gör att buffrade data skrivs Listeners till samlingen.
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 ()
- Attribut
Exempel
I följande exempel skapas ett TextWriterTraceListener med namnet myTextListener.
myTextListener använder en FileStream anropad myFileStream för att skriva till en fil med namnet TestFile.txt. Exemplet skapar strömmen, öppnar filen om den finns eller skapar en ny, skriver en textrad till filen och rensar och stänger sedan utdata.
// 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
Kommentarer
Om dataströmmen töms töms inte dess underliggande kodare om du inte uttryckligen anropar Flush eller Close.
AutoFlush Inställningen true innebär att data rensas från bufferten till strömmen, men kodartillståndet rensas inte. Detta gör att kodaren kan behålla sitt tillstånd (partiella tecken) så att nästa teckenblock kan kodas korrekt. Det här scenariot påverkar UTF8 och UTF7 där vissa tecken bara kan kodas efter att kodaren har fått det intilliggande tecknet eller tecknen.