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 7413703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:56:48+00:00 2026-05-29T06:56:48+00:00

What is difference between the below ThreadPool.QueueUserWorkItem vs Task.Factory.StartNew If the above code is

  • 0

What is difference between the below

ThreadPool.QueueUserWorkItem

vs

Task.Factory.StartNew

If the above code is called 500 times for some long running task, does it mean all the thread pool threads will be taken up?

Or will TPL (2nd option) be smart enough to just take up threads less or equal to number of processors?

  • 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-29T06:56:48+00:00Added an answer on May 29, 2026 at 6:56 am

    If you’re going to start a long-running task with TPL, you should specify TaskCreationOptions.LongRunning, which will mean it doesn’t schedule it on the thread-pool. (EDIT: As noted in comments, this is a scheduler-specific decision, and isn’t a hard and fast guarantee, but I’d hope that any sensible production scheduler would avoid scheduling long-running tasks on a thread pool.)

    You definitely shouldn’t schedule a large number of long-running tasks on the thread pool yourself. I believe that these days the default size of the thread pool is pretty large (because it’s often abused in this way) but fundamentally it shouldn’t be used like this.

    The point of the thread pool is to avoid short tasks taking a large hit from creating a new thread, compared with the time they’re actually running. If the task will be running for a long time, the impact of creating a new thread will be relatively small anyway – and you don’t want to end up potentially running out of thread pool threads. (It’s less likely now, but I did experience it on earlier versions of .NET.)

    Personally if I had the option, I’d definitely use TPL on the grounds that the Task API is pretty nice – but do remember to tell TPL that you expect the task to run for a long time.

    EDIT: As noted in comments, see also the PFX team’s blog post on choosing between the TPL and the thread pool:

    In conclusion, I’ll reiterate what the CLR team’s ThreadPool developer has already stated:

    Task is now the preferred way to queue work to the thread pool.
    

    EDIT: Also from comments, don’t forget that TPL allows you to use custom schedulers, if you really want to…

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

Sidebar

Related Questions

What is the difference between the below code snippets? Won't both be using threadpool
What's the difference between the two code below. int a[] = {0,0}; int a[2]
What is the difference between the code (i) and (ii) written below ? (i)
Please tell me the difference between stack and heap with respect to below code
Lets say I have the below code. What is the difference between assigning the
I would like to compare difference between two dates, but with the code below
Trying to get the difference between two DateTime objects. With the below code, I
What is the difference between the two pieces of code below? This returns the
What is the difference between the two pieces of code below? Will there be
What is the difference between the two lines of code below: CComPtr< IInterface >

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.