XmlWriter.Flush XmlWriter.Flush XmlWriter.Flush XmlWriter.Flush Method

정의

파생 클래스에서 재정의되면 버퍼에 있는 항목을 내부 스트림으로 플러시하고 내부 스트림도 플러시합니다.When overridden in a derived class, flushes whatever is in the buffer to the underlying streams and also flushes the underlying stream.

public:
 abstract void Flush();
public abstract void Flush ();
abstract member Flush : unit -> unit
Public MustOverride Sub Flush ()

예외

이전 비동기 작업이 완료되기 전에 XmlWriter 메서드가 호출되었습니다.An XmlWriter method was called before a previous asynchronous operation finished. 이 경우 “비동기 작업이 이미 진행 중입니다.” 메시지를 나타내며 InvalidOperationException이 throw됩니다.In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

예제

다음 예제에서는 두 개의 XML 조각을 씁니다.The following example writes two XML fragments.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
void main()
{
   
   // Create an XmlWriter to write XML fragments.
   XmlWriterSettings^ settings = gcnew XmlWriterSettings;
   settings->ConformanceLevel = ConformanceLevel::Fragment;
   settings->Indent = true;
   XmlWriter^ writer = XmlWriter::Create( Console::Out, settings );
   
   // Write an XML fragment.
   writer->WriteStartElement( L"book" );
   writer->WriteElementString( L"title", L"Pride And Prejudice" );
   writer->WriteEndElement();
   writer->Flush();
   
   // Write another XML fragment.
   writer->WriteStartElement( L"cd" );
   writer->WriteElementString( L"title", L"Americana" );
   writer->WriteEndElement();
   writer->Flush();
   
   // Close the writer.
   writer->Close();
}

using System;
using System.IO;
using System.Xml;

public class Sample {

  public static void Main() {
 
     // Create an XmlWriter to write XML fragments.
     XmlWriterSettings settings = new XmlWriterSettings();
     settings.ConformanceLevel = ConformanceLevel.Fragment;
     settings.Indent = true;
     XmlWriter writer = XmlWriter.Create(Console.Out, settings);
     
     // Write an XML fragment.
     writer.WriteStartElement("book");
     writer.WriteElementString("title", "Pride And Prejudice");
     writer.WriteEndElement();
     writer.Flush();

     // Write another XML fragment.
     writer.WriteStartElement("cd");
     writer.WriteElementString("title", "Americana");
     writer.WriteEndElement();
     writer.Flush();  

     // Close the writer.
     writer.Close();
  }
}
Imports System.IO
Imports System.Xml

Public Class Sample

  Public Shared Sub Main()

     ' Create an XmlWriter to write XML fragments.
     Dim settings As XmlWriterSettings = new XmlWriterSettings()
     settings.ConformanceLevel = ConformanceLevel.Fragment
     settings.Indent = true
     Dim writer As XmlWriter = XmlWriter.Create(Console.Out, settings)
	
     ' Write an XML fragment.
     writer.WriteStartElement("book")
     writer.WriteElementString("title", "Pride And Prejudice")
     writer.WriteEndElement()
     writer.Flush()

     ' Write another XML fragment.
     writer.WriteStartElement("cd")
     writer.WriteElementString("title", "Americana")
     writer.WriteEndElement()
     writer.Flush()  

     'Close the writer.
     writer.Close()

  End Sub
End Class

설명

대신 이것을 Close 버퍼에 있는 내용을 손실 하지 않고 내부 스트림에 자세히 작성 하려는 경우.This is called instead of Close when you want to write more to the underlying stream without losing what is still in the buffer.

이 메서드의 비동기 버전을 참조 하세요. FlushAsync합니다.For the asynchronous version of this method, see FlushAsync.

적용 대상