Muokkaa

Jaa


IsolatedStorageFileStream.Close Method

Definition

Releases resources associated with the IsolatedStorageFileStream object.

public:
 override void Close();
public override void Close ();
override this.Close : unit -> unit
Public Overrides Sub Close ()

Examples

The following code example demonstrates the Close method.

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();
Dim source As New IsolatedStorageFileStream(UserName,FileMode.Open,isoFile)
 ' This stream is the one that data will be read from
 If source.CanRead Then
     Console.WriteLine("Source can read ? true")
 Else
     Console.WriteLine("Source can read ? false")
 End If
 Dim target As New IsolatedStorageFileStream("Archive\\ " & UserName, _
                                             FileMode.OpenOrCreate, _
                                             isoFile)
 ' This stream is the one that data will be written to
 If target.CanWrite Then
     Console.WriteLine("Target is writable? true")
 Else
     Console.WriteLine("Target is writable? false")
 End If
 ' 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