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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:32:15+00:00 2026-06-08T13:32:15+00:00

I am trying to understand how ThreadPool.QueueWorkItem method works. But couldn’t understand how it

  • 0

I am trying to understand how ThreadPool.QueueWorkItem method works. But couldn’t understand how it is working.

I create a simple example to test ThreadPool, when I run this code it loop quickly and stoped at Thread.Sleep() line. So what does ThreadPool do in here. Does it store 10000 method in an internal collection then execute them asynchronously. (according to some calculation internally thread count can be anything=> this is what I know)

  1. If there is a queue (It should be), Can I get the count of the items (methods) that is waiting on queue?

2.In example WriteLine method is simple, but in my real appllication I am looping over 50000 items and call web service methods, database select/insert/update vb.. for each item in an array. Is it possible to do this type of thing like that?

class Program
{
    static void Main(string[] args)
    {
        new Program().Looper();
    }

    public void Looper()
    {
        for (int i = 0; i < 10000; i++)
        {
            ThreadPool.QueueUserWorkItem(WriteLine, i);
        }

        Thread.Sleep(10000);
    }

    public void WriteLine(object str)
    {
        Debug.WriteLine((int)str);
    }
}
  • 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-06-08T13:32:16+00:00Added an answer on June 8, 2026 at 1:32 pm

    1) If there is a queue (It should be), Can I get the count of the items (methods) that is waiting on queue?

    Yes there is a queue, and no you cannot see it. It is an implementation detail of the ThreadPool, and you wouldn’t really be able to do anything with it anyway.

    2.In example WriteLine method is simple, but in my real appllication I am looping over 50000 items and call web service methods, database select/insert/update vb.. for each item in an array. Is it possible to do this type of thing like that?

    Yes, and it sounds like it might be a good candidate for pooled execution because it involves a lot of waiting on external resources. That said, if you are on .NET 4.0 or higher you may want to look at TPL instead of accessing the threadpool yourself. TPL gives you features like Task nesting and continuation which you don’t get with the ThreadPool. It also natively integrates with Async patterns, giving you improved async I/O parallelism.

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

Sidebar

Related Questions

Trying to understand the options for will_paginate's paginate method: :page — REQUIRED, but defaults
I am trying to understand what ThreadPool does, I have this .NET example: class
Trying to understand, why my C++/Qt application creates 18 threads, while i don't create
Trying to understand how EDE works by using it to generate Makefiles for a
I'm trying understand how try ... catch construction works in T-SQL. So I've read
Trying to understand upcasting in Java. Recently observed strange behavior. Example: public class A
Trying to understand how CoffeeScript instance and class variable works I came with this
I am trying understand how multi queries work in mysqli. But I confess that
HI Trying to understand how __radd__ works. I have the code >>> class X(object):
Trying to understand the relationship between UIView and CALayer. I read Apple documentation but

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.