IsolatedStorageFileStream.Close Metod

Definition

Frigör resurser som är associerade med IsolatedStorageFileStream objektet.

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

Exempel

I följande kodexempel visas metoden Stäng.

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()

Kommentarer

Data som tidigare skrivits till bufferten kopieras till filen innan filströmmen stängs, så det är inte nödvändigt att anropa Flush innan du anropar Stäng.

Efter ett anrop till Stäng kan alla åtgärder i filströmmen generera undantag. När Close har anropats en gång, gör det ingenting om det anropas igen. Metoden Finalize() anropar Stäng så att filströmmen stängs innan skräpinsamlaren slutför objektet.

IsolatedStorageFileStream objekt kräver ett IsolatedStorageFile objekt som avgör lagringskontexten för de filer som används. För strömmar som öppnas utan att skicka ett IsolatedStorageFile objekt skapas ett standardobjekt IsolatedStorageFile för den körande sammansättningen och stängs sedan under anropet till Stäng.

Note

Metoden Close anropar Dispose med disponering inställd på true för att frigöra sina resurser och anropar SuppressFinalize sedan för att förhindra att objektet slutförs av skräpinsamlaren.

Gäller för