Partager via


Task.Dispose Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Releases all resources used by the current instance of the Task class.

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

Syntax

'Declaration
Public Sub Dispose
public void Dispose()

Implements

IDisposable.Dispose()

Exceptions

Exception Condition
InvalidOperationException

The exception that is thrown if the Task is not in one of the final states: RanToCompletion, Faulted, or Canceled.

Remarks

Call Dispose when you are finished using the Task. The Dispose method leaves the Task in an unusable state. After calling Dispose, you must release all references to the Task so the garbage collector can reclaim the memory that the Task was occupying.

For more information, see Cleaning Up Unmanaged Resources and Implementing a Dispose Method.

NoteNote:

Always call Dispose before you release your last reference to the Task. Otherwise, the resources it is using will not be freed until the garbage collector calls the Task object's Finalize method.

Version Information

Silverlight

Supported in: 5

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.