You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: xml/System/IAsyncDisposable.xml
+47-6Lines changed: 47 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -15,8 +15,34 @@
15
15
</AssemblyInfo>
16
16
<Interfaces />
17
17
<Docs>
18
-
<summary>To be added.</summary>
19
-
<remarks>To be added.</remarks>
18
+
<summary>Provides a mechanism for releasing unmanaged resources asynchronously.</summary>
19
+
<remarks>
20
+
<formattype="text/markdown">< or [Asynchronous Programming with Async and Await (Visual Basic)](/dotnet/visual-basic/programming-guide/concepts/async/).
29
+
30
+
### Using an object that implements IAsyncDisposable
31
+
32
+
If your application uses an object that implements `IAsyncDisposable`, you should call the object's <xref:System.IAsyncDisposable.DisposeAsync%2A> implementation when you are finished using it. To make sure resources are released even in case of an exception, call the <xref:System.IAsyncDisposable.DisposeAsync%2A> method inside a `finally` clause of the `try`/`finally` statement. For more information about the `try`/`finally` pattern, see [try-finally](~/docs/csharp/language-reference/keywords/try-finally.md) (C#) or [Try...Catch...Finally Statement](~/docs/visual-basic/language-reference/statements/try-catch-finally-statement.md) (Visual Basic).
33
+
34
+
### Implementing IAsyncDisposable
35
+
36
+
You might implement `IAsyncDisposable` in the following situations:
37
+
38
+
- When developing an asynchronous enumerator that owns unmanaged resources. Asynchronous enumerators are used with the C# 8.0 async streams feature. For more information about async streams, see [Tutorial: Generate and consume async streams using C# 8.0 and .NET Core 3.0](/dotnet/csharp/tutorials/generate-consume-asynchronous-stream).
39
+
40
+
- When your class owns unmanaged resources and releasing them requires a resource-intensive I/O operation, such as flushing the contents of an intermediate buffer into a file or sending a packet over a network to close a connection.
41
+
42
+
Use the <xref:System.IAsyncDisposable.DisposeAsync%2A> method to perform whatever cleanup is necessary after using the unmanaged resources, such as freeing, releasing, or resetting the unmanaged resources. For more information about unmanaged resources in .NET, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged).
43
+
44
+
]]></format>
45
+
</remarks>
20
46
</Docs>
21
47
<Members>
22
48
<MemberMemberName="DisposeAsync">
@@ -40,10 +66,25 @@
40
66
</ReturnValue>
41
67
<Parameters />
42
68
<Docs>
43
-
<summary>To be added.</summary>
44
-
<returns>To be added.</returns>
45
-
<remarks>To be added.</remarks>
69
+
<summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.</summary>
70
+
<returns>A task that represents the asynchronous dispose operation.</returns>
71
+
<remarks>
72
+
<formattype="text/markdown"><![CDATA[
73
+
74
+
## Remarks
75
+
76
+
Use this method to asynchronously close or release unmanaged resources such as files, streams, and handles held by an instance of the class that implements this interface. Using this method instead of <xref:System.IDisposable.Dispose%2A?displayProperty=nameWithType> enables you to perform a resource-intensive dispose operation without blocking the main thread of a GUI application for a long time.
77
+
78
+
> [!WARNING]
79
+
> If you are using a class that implements the <xref:System.IAsyncDisposable> interface, you should call its `DisposeAsync` implementation when you are finished using the class. For more information, see the "Using an object that implements IAsyncDisposable" section in the <xref:System.IAsyncDisposable> topic.
80
+
81
+
When implementing this method, ensure that all held resources are freed by propagating the call through the containment hierarchy. For example, if an object A allocates an object B, and object B allocates an object C, then A's `DisposeAsync` implementation must call `DisposeAsync` on B, which must in turn call `DisposeAsync` on C. An object must also call the `DisposeAsync` method of its base class if the base class implements <xref:System.IAsyncDisposable>.
82
+
83
+
If an object's `DisposeAsync` method is called more than once, the object must ignore all calls after the first one and synchronously return a successfully completed <xref:System.Threading.Tasks.ValueTask>. The object must not throw an exception if its `DisposeAsync` method is called multiple times. Instance methods other than `DisposeAsync` can throw an <xref:System.ObjectDisposedException> when resources are already disposed.
0 commit comments