IsolatedStorageFile.Dispose Method
Releases all resources used by the IsolatedStorageFile.
Namespace: System.IO.IsolatedStorage
Assembly: mscorlib (in mscorlib.dll)
Call Dispose when you are finished using the IsolatedStorageFile. The Dispose method leaves the IsolatedStorageFile in an unusable state. After calling Dispose, you must release all references to the IsolatedStorageFile so the garbage collector can reclaim the memory that IsolatedStorageFile was occupying.
Note |
|---|
Always call Dispose before you release your last reference to the IsolatedStorageFile. Otherwise, the resources the IsolatedStorageFileStream is using will not be freed until garbage collection calls the IsolatedStorageFileStream object's Finalize method. |
The following code example opens an isolated storage file, uses it to write information to a stream, closes the file, and then uses the Dispose method to release all resources.
IsolatedStorageFile isoFile; isoFile = IsolatedStorageFile.GetUserStoreForDomain(); // Open or create a writable file. IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(this.userName, FileMode.OpenOrCreate, FileAccess.Write, isoFile); StreamWriter writer = new StreamWriter(isoStream); writer.WriteLine(this.NewsUrl); writer.WriteLine(this.SportsUrl); // Calculate the amount of space used to record the user's preferences. double d = isoFile.CurrentSize / isoFile.MaximumSize; Console.WriteLine("CurrentSize = " + isoFile.CurrentSize.ToString()); Console.WriteLine("MaximumSize = " + isoFile.MaximumSize.ToString()); // StreamWriter.Close implicitly closes isoStream. writer.Close(); isoFile.Dispose(); isoFile.Close(); return d;
- ReflectionPermission
when invoked late-bound through mechanisms such as Type.InvokeMember. Associated enumeration: ReflectionPermissionFlag.MemberAccess
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note