Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1089115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:10:19+00:00 2026-05-16T23:10:19+00:00

I want to trigger a task to run on a background thread. I don’t

  • 0

I want to trigger a task to run on a background thread. I don’t want to wait on the tasks completion.

In .net 3.5 I would have done this:

ThreadPool.QueueUserWorkItem(d => { DoSomething(); });

In .net 4 the TPL is the suggested way. The common pattern I have seen recommended is:

Task.Factory.StartNew(() => { DoSomething(); });

However, the StartNew() method returns a Task object which implements IDisposable. This
seems to be overlooked by people who recommend this pattern. The MSDN documentation on the Task.Dispose() method says:

“Always call Dispose before you release your last reference to the Task.”

You can’t call dispose on a task until it is completed, so having the main thread wait and call dispose would defeat the point of doing on a background thread in the first place. There also doesn’t seem to be any completed/finished event that could be used for cleanup.

The MSDN page on the Task class doesn’t comment on this, and the book “Pro C#2010…” recommends the same pattern and makes no comment on task disposal.

I know if I just leave it the finalizer will catch it in the end, but is this going to come back and bite me when I’m doing lots of fire & forget tasks like this and the finalizer thread gets overwhelmed?

So my questions are:

  • Is it acceptable to not call Dispose() on the Task class in this case? And if so, why and are there risks/consequences?
  • Is there any documentation that discusses this?
  • Or is there an appropriate way of disposing of the Task object that I’ve missed?
  • Or is there another way of doing fire & forget tasks with the TPL?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:10:20+00:00Added an answer on May 16, 2026 at 11:10 pm

    There is a discussion about this in the MSDN forums.

    Stephen Toub, a member of the Microsoft pfx team has this to say:

    Task.Dispose exists due to Task
    potentially wrapping an event handle
    used when waiting on the task to
    complete, in the event the waiting
    thread actually has to block (as
    opposed to spinning or potentially
    executing the task it’s waiting on).
    If all you’re doing is using
    continuations, that event handle will
    never be allocated
    …
    it’s likely better to rely on finalization to take care of things.

    Update (Oct 2012)
    Stephen Toub has posted a blog titled Do I need to dispose of Tasks? which gives some more detail, and explains the improvements in .Net 4.5.

    In summary: You don’t need to dispose of Task objects 99% of the time.

    There are two main reasons to dispose an object: to free up unmanaged resources in a timely, deterministic way, and to avoid the cost of running the object’s finalizer. Neither of these apply to Task most of the time:

    1. As of .Net 4.5, the only time a Task allocates the internal wait handle (the only unmanaged resource in the Task object) is when you explicitly use the IAsyncResult.AsyncWaitHandle of the Task, and
    2. The Task object itself doesn’t have a finalizer; the handle is itself wrapped in an object with a finalizer, so unless it’s allocated, there’s no finalizer to run.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to trigger a long running background process (coded as a service) from
I have an click function that I want to trigger outside of the function
I have a div, containing text and a few links. I want to trigger
We are using Task in our application. In one class we want to trigger
I want my program to continuously wait for a trigger in order to perform
Background: I have a JScript that runs when the computer starts up (from task
I would like to sync my db (tasks on my db, that have a
I want to create a process in my ASP.NET application that I trigger manually
I have simple PyGTK app. Since I have to run multiple periodic tasks to
I want to provide status updates during a long-running task on an ASP.NET WebForms

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.