Home > other >  C# .Net Framework Disposing of Tasks
C# .Net Framework Disposing of Tasks

Time:01-29

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;
}

CodePudding user response:

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.

  •  Tags:  
  • Related