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

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

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

public void Dispose()

Implements

IDisposable.Dispose()

ExceptionCondition
InvalidOperationException

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

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.

Silverlight

Supported in: 5

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

Community Additions

ADD
Show:
© 2015 Microsoft