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

  • Home
  • SEARCH
  • 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 4608476
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:51:02+00:00 2026-05-22T00:51:02+00:00

I am having fun working with System.Threading.Tasks . Many of the code samples I

  • 0

I am having fun working with System.Threading.Tasks. Many of the code samples I see, however, look something like so:

Dim lcTask = Task.Factory.StartNew(Sub() DoSomeWork())
Dim lcTaskLong = Task.Factory.StartNew(Sub() DoSomeWork(), TaskCreationOptions.LongRunning)
Task.WaitAll(lcTask, lcTaskLong)

That’s the extent of the sample.
Tasks implement IDisposable, so obviously I’m supposed to dispose of them, but what if I just want to “Fire and Forget”?

If I don’t dispose, will I leak threads/handles/memory/karma?
Am I using tasks “wrong”? (Should just use a delegate and leave tasks alone?)

Can I dispose in a ContinueWith()? (That seems like playing Russian Roulette.)

  • 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-22T00:51:02+00:00Added an answer on May 22, 2026 at 12:51 am

    While the normal rule of thumb is to always call Dispose() on all IDisposable implementations, Task and Task<T> are often one case where it’s better to let the finalizer take care of this.

    The reason Task implements IDisposable is mainly due to an internal WaitHandle. This is required to allow task continuations to work properly, and only used when there is a continuation on a Task. If there is no continuation, the Task’s Dispose method has no real effect – so in this case, it’s not required.

    That being said, in most cases where there is a Task continuation, it’s often very, very difficult to write your code in a way that allows you to properly call Dispose(). Using statements typically do not work with Task instances, since the Task call is typically asynchronous in nature. It’s very easy to dispose of the Task far too early, especially when using the using statement.

    If, in your case, it’s relatively simple to keep a reference to the Task and call Dispose() on it correctly, I would do so. However, if this is going to cause your logic to get much more complex, I would typically pretend that Task isn’t IDisposable, and allow it to be cleaned up in the finalizer for the Task.

    For more details, I’d recommend reading this thread on the MSDN forums where Stephen Toub describes why Task implements IDisposable in detail, and provides similar guidance to my suggestion above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having tons of fun working on a big project that was, for
I am beginning some experimentation in writing a kernel and having fun doing it.
I'm having some fun trying to get my head around some MVP stuf, as
We're having a bit of fun here at work. It all started with one
so I'm having a lot of fun with Perl at home for some time
Having a heckuva time with this one, though I feel I'm missing something obvious.
Having a problem getting a TreeView control to display node images. The code below
I'm working with the C# managed wiimote library for a little fun project I'm
I'm currently having fun trying to learn some of the Boost libary. I'm currently
I am having fun with google maps and was after some assistance. Basically I

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.