This documentation is archived and is not being maintained.

ResourceWriter.Dispose Method

Allows users to close the resource file or stream, explicitly releasing resources.

[Visual Basic]
Public Overridable Sub Dispose() Implements IDisposable.Dispose
[C#]
public virtual void Dispose();
[C++]
public: virtual void Dispose();
[JScript]
public function Dispose();

Implements

IDisposable.Dispose

Exceptions

Exception Type Condition
IOException An I/O error has occurred.
SerializationException An error has occurred during serialization of the object.

Remarks

The implementation of this method is the same as Close.

Example

[Visual Basic] 
Imports System
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

[C#] 
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();
    }
}

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

using namespace System;
using namespace System::Resources;
using namespace System::IO;


int main() {
    // Create a file stream to encapsulate items.resources.
    FileStream* fs = new FileStream(S"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(S"String 1", S"First String");
    writer->AddResource(S"String 2", S"Second String");
    writer->AddResource(S"String 3", S"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();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ResourceWriter Class | ResourceWriter Members | System.Resources Namespace | IDisposable

Show: