Language

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

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

Note

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

適用対象