Прочетете на английски Редактиране

Споделяне чрез


IsolatedStorageFile.Dispose Method

Definition

Releases all resources used by the IsolatedStorageFile.

C#
public void Dispose();

Implements

Examples

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.

C#
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;

Remarks

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.

Бележка

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.

Applies to

Продукт Версии
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

See also