다음을 통해 공유


ResourceWriter.Dispose 메서드

정의

리소스 파일 또는 스트림을 닫아서 명시적으로 리소스를 해제할 수 있습니다.

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

구현

예외

I/O 오류가 발생했습니다.

개체를 serialize하는 동안 오류가 발생한 경우

예제

다음 코드 예제에서는 메서드를 사용하여 클래스의 Dispose 모든 리소스 개체를 ResourceWriter 출력 스트림에 씁니다. 그런 다음, 코드는 기록기를 종료하고 기록기 리소스를 다른 프로세스에 사용할 수 있도록 합니다.

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

설명

이 메서드의 구현은 와 동일합니다 Close.

적용 대상

추가 정보