Debug.Flush 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
刷新输出缓冲区并导致缓冲的数据写入 Listeners 集合。
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 ()
- 属性
示例
以下示例创建一个 TextWriterTraceListener 命名的 myTextListener。
// 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
注解
除非显式调用 Flush 或 Close调用流,否则刷新流不会刷新其基础编码器。
AutoFlush设置为true表示数据将从缓冲区刷新到流,但不会刷新编码器状态。 这使编码器能够保持其状态(部分字符),以便它可以正确编码下一个字符块。 此方案影响 UTF8 和 UTF7,其中某些字符只能在编码器接收相邻字符或字符后进行编码。