ResourceWriter.Dispose Método
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Permite que os usuários fechem o fluxo ou o arquivo de recurso, liberando recursos explicitamente.
public:
virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()
Implementações
Exceções
Ocorreu um erro de E/S.
Ocorreu um erro durante a serialização do objeto.
Exemplos
O exemplo de código a seguir usa o Dispose método para gravar todos os objetos de recurso em uma ResourceWriter classe no fluxo de saída. Em seguida, o código desliga o gravador e disponibiliza os recursos do gravador para outros processos.
using namespace System;
using namespace System::Resources;
using namespace System::IO;
int main()
{
// Create a file stream to encapsulate items.resources.
FileStream^ fs = gcnew FileStream( "items.resources",FileMode::OpenOrCreate,FileAccess::Write );
// Open a resource writer to write from the stream.
IResourceWriter^ writer = gcnew ResourceWriter( fs );
// Add resources to the resource writer.
writer->AddResource( "String 1", "First String" );
writer->AddResource( "String 2", "Second String" );
writer->AddResource( "String 3", "Third String" );
// Write the resources to the stream,
// and clean up all resources associated with the writer.
// Calling Dispose is equivalent to calling Close.
writer->~IResourceWriter();
}
using System;
using System.Resources;
using System.IO;
public class WriteResources
{
public static void Main(string[] args)
{
// Create a file stream to encapsulate items.resources.
FileStream fs = new FileStream("items.resources",
FileMode.OpenOrCreate,FileAccess.Write);
// Open a resource writer to write from the stream.
IResourceWriter writer = new ResourceWriter(fs);
// Add resources to the resource writer.
writer.AddResource("String 1", "First String");
writer.AddResource("String 2", "Second String");
writer.AddResource("String 3", "Third String");
// Write the resources to the stream,
// and clean up all resources associated with the writer.
// Calling Dispose is equivalent to calling Close.
writer.Dispose();
}
}
Imports System.Resources
Imports System.IO
Public Class WriteResources
Public Shared Sub Main(ByVal args() As String)
' Create a file stream to encapsulate items.resources.
Dim fs As New FileStream("items.resources", _
FileMode.OpenOrCreate, FileAccess.Write)
' Open a resource writer to write from the stream.
Dim writer = New ResourceWriter(fs)
' Add resources to the resource writer.
writer.AddResource("String 1", "First String")
writer.AddResource("String 2", "Second String")
writer.AddResource("String 3", "Third String")
' Write the resources to the stream,
' and clean up all resources associated with the writer.
' Calling Dispose is equivalent to calling Close.
writer.Dispose()
End Sub
End Class
Comentários
A implementação desse método é a mesma que Close.