XmlWriter.Flush Metoda

Definice

Při přepsání v odvozené třídě vyprázdní cokoli, co je ve vyrovnávací paměti, do podkladových datových proudů a také vyprázdní základní datový proud.

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

Výjimky

Před XmlWriter dokončením předchozí asynchronní operace byla volána metoda. V tomto případě InvalidOperationException je vyvolán zpráva "Asynchronní operace už probíhá".

Příklady

Následující příklad zapíše dva fragmenty XML.

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

Poznámky

To se volá místo Close toho, když chcete napsat více do podkladového datového proudu, aniž byste ztratili to, co je stále ve vyrovnávací paměti.

Asynchronní verzi této metody naleznete v tématu FlushAsync.

Platí pro