IsolatedStorageFileStream.Close Metoda

Definicja

Zwalnia zasoby skojarzone z obiektem IsolatedStorageFileStream .

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

Przykłady

Poniższy przykład kodu przedstawia metodę 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()

Uwagi

Wszystkie dane zapisane wcześniej w buforze są kopiowane do pliku przed zamknięciem strumienia plików, więc nie jest konieczne wywołanie Flush przed wywołaniem funkcji Close.

Po wywołaniu metody Close wszelkie operacje w strumieniu plików mogą zgłaszać wyjątki. Po Close wywołaniu raz nie robi nic, jeśli zostanie wywołana ponownie. Metoda Finalize() wywołuje metodę Close, aby strumień pliku został zamknięty przed sfinalizowanie obiektu przez moduł odśmiecywania pamięci.

IsolatedStorageFileStream obiekty wymagają IsolatedStorageFile obiektu, który określa kontekst magazynu dla plików, do których uzyskiwano dostęp. W przypadku strumieni otwartych bez przekazywania IsolatedStorageFile obiektu domyślny IsolatedStorageFile obiekt jest tworzony dla zestawu wykonawczego, a następnie zamykany podczas wywoływania do zamknięcia.

Uwaga

Metoda Close wywołuje Dispose metodę z wartością true w celu zwolnienia jej zasobów, a następnie wywołuje metodę SuppressFinalize pomijania finalizacji tego obiektu przez moduł odśmiecania pamięci.

Dotyczy