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()
Комментарии
Все данные, ранее записанные в буфер, копируются в файл перед закрытием потока файлов, поэтому не нужно вызывать перед вызовом Flush Close.
После вызова Close все операции в потоке файлов могут вызывать исключения. После Close того, как он был вызван один раз, он ничего не делает, если снова вызывается. Метод Finalize() вызывает Close, чтобы файловый поток был закрыт, прежде чем сборщик мусора завершит объект.
IsolatedStorageFileStream для объектов требуется объект, определяющий IsolatedStorageFile контекст хранилища для доступа к файлам. Для потоков, открытых без передачи IsolatedStorageFile объекта, для выполняемой сборки создается объект по умолчанию IsolatedStorageFile , а затем закрывается во время вызова close.
Note
Метод Close вызывает Dispose метод с присвоением значения true, чтобы освободить ресурсы, а затем вызывает SuppressFinalize подавление завершения этого объекта сборщиком мусора.