IsolatedStorageFileStream.Close メソッド

定義

IsolatedStorageFileStream オブジェクトに関連付けられたリソースを解放します。

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

次のコード例は、Close メソッドを示しています。

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

注釈

バッファーに以前に書き込まれたデータは、ファイル ストリームが閉じられる前にファイルにコピーされるため、Close を呼び出す前に を呼び出 Flush す必要はありません。

Close の呼び出しの後、ファイル ストリームに対するすべての操作で例外が発生する可能性があります。 が 1 回呼び出された後 Close 、再度呼び出された場合は何も行いません。 メソッドは Finalize() Close を呼び出して、ガベージ コレクターがオブジェクトを終了する前にファイル ストリームを閉じます。

IsolatedStorageFileStream オブジェクトには、 IsolatedStorageFile アクセスされるファイルのストレージ コンテキストを決定する オブジェクトが必要です。 オブジェクトを IsolatedStorageFile 渡さずに開かれたストリームの場合、実行中のアセンブリに対して既定 IsolatedStorageFile のオブジェクトが作成され、Close の呼び出し中に閉じられます。

注意

メソッドは Close 、disposing を true に設定して を呼び出 Dispose してリソースを解放し、 を呼び出 SuppressFinalize してガベージ コレクターによるこのオブジェクトの最終処理を抑制します。

適用対象