Sari Rahal
Sari Rahal

Reputation: 1955

C# .Net Framework Disposing of Tasks

I was wondering if there are any benefits to implementing the dispose feature for Tasks. Will this operate any different? Will this force the memory to clean up any faster?

Task updateTask = UpdateRemoteAsync()
await updateTask;

VS

using (Task updateTask = UpdateRemoteAsync())
{
    await updateTask;
}

Upvotes: 2

Views: 230

Answers (1)

HMZ
HMZ

Reputation: 3127

In most cases no, when you dispose of a Task you are disposing the WaitHandle they allocate, and according to Microsoft, Since .NET Framework 4.5 the async/await functionality, WaitAll and WaitAny doesn't allocate one at all unless you explicitly need to require IAsyncResult.AsyncWaitHandle.

Further reading: MS Dev Blog.

Upvotes: 6

Related Questions