ResourceWriter.Dispose Method ()

 

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

Namespace:   System.Resources
Assembly:  mscorlib (in mscorlib.dll)

public void Dispose()

Exception Condition
IOException

An I/O error has occurred.

SerializationException

An error has occurred during serialization of the object.

The implementation of this method is the same as Close.

The following code example uses the Dispose method to write all resource objects in a ResourceWriter class to the output stream. The code then shuts down the writer and make the writer's resources available for other processes.

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();
    }
}

.NET Framework
Available since 1.1
Return to top
Show: