IsolatedStorageFileStream.Close 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
釋放與 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()
備註
先前寫入緩衝區的資料會在檔案串流關閉前先複製到檔案,因此在呼叫關閉前不必先呼叫 Flush 。
在呼叫關閉後,檔案串流上的任何操作都可能會觸發例外。
Close被叫過一次後,如果再叫一次就不會有反應。 此 Finalize() 方法會呼叫 Close,讓檔案串流在垃圾回收器最終完成物件前就已關閉。
IsolatedStorageFileStream 物件需要一個 IsolatedStorageFile 物件來決定所存取檔案的儲存上下文。 對於未傳遞 IsolatedStorageFile 物件而開啟的串流,會為執行中的組裝建立一個預設 IsolatedStorageFile 物件,並在呼叫關閉時關閉。
Note
該方法將 CloseDispose disposing 設為 true 來釋放其資源,接著呼叫 SuppressFinalize 以抑制垃圾回收器對該物件的最終化。