IsolatedStorageFileStream.Close Method

Definition

Releases resources associated with the IsolatedStorageFileStream object.

C#
public override void Close();

Examples

The following code example demonstrates the Close method.

C#
IsolatedStorageFileStream source =
     new IsolatedStorageFileStream(this.userName,FileMode.Open,isoFile);
 // This stream is the one that data will be read from
 Console.WriteLine("Source can be read?" + (source.CanRead?"true":"false"));
 IsolatedStorageFileStream target =
     new IsolatedStorageFileStream("Archive\\ " + this.userName,FileMode.OpenOrCreate,isoFile);
 // This stream is the one that data will be written to
 Console.WriteLine("Target is writable?" + (target.CanWrite?"true":"false"));
 // Do work...
 // After you have read and written to the streams, close them
 source.Close();
 target.Close();

Remarks

Any data previously written to the buffer is copied to the file before the file stream is closed, so it is not necessary to call Flush before invoking Close.

Following a call to Close, any operations on the file stream might raise exceptions. After Close has been called once, it does nothing if called again. The Finalize() method invokes Close so the file stream is closed before the garbage collector finalizes the object.

IsolatedStorageFileStream objects require an IsolatedStorageFile object that determines the storage context for the files accessed. For streams opened without passing an IsolatedStorageFile object, a default IsolatedStorageFile object is created for the executing assembly and then closed during the call to Close.

Note

The Close method calls Dispose with disposing set to true to release its resources, then calls SuppressFinalize to suppress finalization of this object by the garbage collector.

Applies to

Product Versions
.NET Framework 1.1