Debug.Flush Método
Definição
public:
static void Flush();
[System.Diagnostics.Conditional("DEBUG")]
public static void Flush ();
public static void Flush ();
[<System.Diagnostics.Conditional("DEBUG")>]
static member Flush : unit -> unit
static member Flush : unit -> unit
Public Shared Sub Flush ()
- Atributos
Exemplos
O exemplo a seguir cria um TextWriterTraceListener nome myTextListener .The following example creates a TextWriterTraceListener named myTextListener. myTextListener usa um FileStream chamado myFileStream para gravar em um arquivo chamado TestFile.txt .myTextListener uses a FileStream called myFileStream to write to a file named TestFile.txt. O exemplo cria o fluxo, abre o arquivo se ele existir ou cria um novo, grava uma linha de texto no arquivo e, em seguida, libera e fecha a saída.The example creates the stream, opens the file if it exists or creates a new one, writes one line of text to the file, and then flushes and closes the output.
// 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
Comentários
A liberação do fluxo não liberará seu codificador subjacente, a menos que você chame explicitamente Flush ou Close .Flushing the stream will not flush its underlying encoder unless you explicitly call Flush or Close. Definir AutoFlush como true significa que os dados serão liberados do buffer para o fluxo, mas o estado do codificador não será liberado.Setting AutoFlush to true means that data will be flushed from the buffer to the stream, but the encoder state will not be flushed. Isso permite que o codificador Mantenha seu estado (caracteres parciais) para que ele possa codificar corretamente o próximo bloco de caracteres.This allows the encoder to keep its state (partial characters) so that it can encode the next block of characters correctly. Esse cenário afeta UTF8 e UTF7, em que determinados caracteres só podem ser codificados depois que o codificador recebe o caractere ou caracteres adjacentes.This scenario affects UTF8 and UTF7 where certain characters can only be encoded after the encoder receives the adjacent character or characters.