次の方法で共有


Debug.Flush メソッド

出力バッファをフラッシュし、バッファ内のデータを Listeners コレクションに書き込みます。

<Conditional("DEBUG")>
Public Shared Sub Flush()
[C#]
[Conditional("DEBUG")]
public static void Flush();
[C++]
[Conditional("DEBUG")]
public: static void Flush();
[JScript]
public
   Conditional("DEBUG")
static function Flush();

解説

ストリームをフラッシュしても、 Flush または Close を明示的に呼び出さない限り、そのストリームの基になるエンコーダはフラッシュされません。 AutoFlushtrue に設定すると、データがバッファからストリームにフラッシュされますが、エンコーダの状態はフラッシュされません。これにより、エンコーダの状態 (一部の文字) を維持できるため、次のブロックの文字を正確にエンコードできるようになります。この動作は、一部の文字をエンコードするためにはエンコーダがあらかじめその文字に隣接する文字を受け取っておく必要がある UTF8 および UTF7 に対して有効です。

使用例

myTextListener という名前の TextWriterTraceListener を作成する例を次に示します。 myTextListener は、 myOutputWriter という名前の StreamWriter を使用して、 TestFile.txt というファイルに書き込みます。この例では、ファイル、ストリーム、およびテキスト ライタを作成し、テキストの 1 行をファイルに書き込んでから、出力をフラッシュして終了します。

 
Overloads Public Shared Sub Main(args() As String)
    ' Create a file for output named TestFile.txt.
    Dim myFileName As String = "TestFile.txt"
    If Not File.Exists(myFileName) Then
        File.Create(myFileName)
    End If 
    
    ' Assign output file to output stream.
    Dim myOutputWriter As StreamWriter
    myOutputWriter = File.AppendText(myFileName)
    
    ' Create a new text writer using the output stream, and
    ' add it to the trace listeners. 
    Dim myTextListener As New TextWriterTraceListener(myOutputWriter)
    Debug.Listeners.Add(myTextListener)
    
    ' Write output to the file.
    Debug.WriteLine("Test output")
    
    ' Flush and close the output stream.
    Debug.Flush()
    Debug.Close()
End Sub 'Main

[C#] 
public static void Main(string[] args) {
    // Create a file for output named TestFile.txt.
    String myFileName = "TestFile.txt";
    if(!File.Exists(myFileName)) 
    File.Create(myFileName);

 
    // Assign output file to output stream.
    StreamWriter myOutputWriter;
    myOutputWriter = File.AppendText(myFileName);
 
    /* Create a new text writer using the output stream, and 
     * add it to the trace listeners. */
    TextWriterTraceListener myTextListener = new 
       TextWriterTraceListener(myOutputWriter);
    Debug.Listeners.Add(myTextListener);
  
    // Write output to the file.
    Debug.WriteLine("Test output");
 
    // Flush and close the output stream.
    Debug.Flush();
    Debug.Close();
 }


[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Diagnostics;

int main(void)
{
    // Create a file for output named TestFile.txt.
    String * myFileName = S"TestFile.txt";
    if ( !File::Exists(myFileName) ) 
        File::Create(myFileName);

    // Assign output file to output stream.
    StreamWriter * myOutputWriter;
    myOutputWriter = File::AppendText(myFileName);
 
    /* Create a new text writer using the output stream, and 
     * add it to the trace listeners. */
    TextWriterTraceListener * myTextListener = new 
       TextWriterTraceListener(myOutputWriter);
    Debug::Listeners->Add(myTextListener);
  
    // Write output to the file.
    Debug::WriteLine(S"Test output");
 
    // Flush and close the output stream.
    Debug::Flush();
    Debug::Close();
}

[JScript] 
public static function Main() {
    // Create a file for output named TestFile.txt.
    var myFileName : String = "TestFile.txt";
    if(!File.Exists(myFileName)) 
    File.Create(myFileName);

 
    // Assign output file to output stream.
    var myOutputWriter : StreamWriter;
    myOutputWriter = File.AppendText(myFileName);
 
    /* Create a new text writer import the output stream and 
     * add it to the trace listeners. */
    var myTextListener : TextWriterTraceListener = new 
       TextWriterTraceListener(myOutputWriter);
    Debug.Listeners.Add(myTextListener);
  
    // Write output to the file.
    Debug.WriteLine("Test output");
 
    // Flush and close the output stream.
    Debug.Flush();
    Debug.Close();
 }

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET

参照

Debug クラス | Debug メンバ | System.Diagnostics 名前空間 | Debug | Trace | BooleanSwitch | TraceSwitch | TraceListener | DefaultTraceListener | ConditionalAttribute