Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Task.Dispose Method (Boolean)

Disposes the Task, releasing all of its unmanaged resources.

Namespace:  System.Threading.Tasks
Assembly:  mscorlib (in mscorlib.dll)

'Declaration
Protected Overridable Sub Dispose ( _
	disposing As Boolean _
)

Parameters

disposing
Type: System.Boolean

A Boolean value that indicates whether this method is being called due to a call to Dispose.

ExceptionCondition
InvalidOperationException

The task is not in one of the final states: TaskStatus.RanToCompletion, TaskStatus.Faulted, or TaskStatus.Canceled.

The Task class implements the IDisposable interface because internally it uses resources that also implement IDisposable. However, particularly if your app targets the .NET Framework 4.5 or later, there is no need to call Dispose unless performance or scalability testing indicates that, based on your usage patterns, your app's performance would be improved by disposing of tasks. For more information, see Do I need to dispose of Tasks? in the Parallel Programming with .NET blog.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4
Show:
© 2015 Microsoft