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.

Примечание

Метод Close вызывает Dispose метод с параметром disposing имеет значение true, чтобы освободить свои ресурсы, а затем вызывает для SuppressFinalize подавления завершения этого объекта сборщиком мусора.

Применяется к