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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:17:25+00:00 2026-05-11T02:17:25+00:00

Looking for some sample code (C#) for a simple thread pool implementation. I found

  • 0

Looking for some sample code (C#) for a simple thread pool implementation.

I found one on codeproject, but the codebase was just huge and I don’t need all that functionality.

This is more for educational purposes anyways.

  • 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. 2026-05-11T02:17:26+00:00Added an answer on May 11, 2026 at 2:17 am

    There is no need to implement your own, since it is not very hard to use the existing .NET implementation.

    From ThreadPool Documentation:

    using System; using System.Threading;  public class Fibonacci {     public Fibonacci(int n, ManualResetEvent doneEvent)     {         _n = n;         _doneEvent = doneEvent;     }      // Wrapper method for use with thread pool.     public void ThreadPoolCallback(Object threadContext)     {         int threadIndex = (int)threadContext;         Console.WriteLine('thread {0} started...', threadIndex);         _fibOfN = Calculate(_n);         Console.WriteLine('thread {0} result calculated...', threadIndex);         _doneEvent.Set();     }      // Recursive method that calculates the Nth Fibonacci number.     public int Calculate(int n)     {         if (n <= 1)         {             return n;         }          return Calculate(n - 1) + Calculate(n - 2);     }      public int N { get { return _n; } }     private int _n;      public int FibOfN { get { return _fibOfN; } }     private int _fibOfN;      private ManualResetEvent _doneEvent; }  public class ThreadPoolExample {     static void Main()     {         const int FibonacciCalculations = 10;          // One event is used for each Fibonacci object         ManualResetEvent[] doneEvents = new ManualResetEvent[FibonacciCalculations];         Fibonacci[] fibArray = new Fibonacci[FibonacciCalculations];         Random r = new Random();          // Configure and launch threads using ThreadPool:         Console.WriteLine('launching {0} tasks...', FibonacciCalculations);         for (int i = 0; i < FibonacciCalculations; i++)         {             doneEvents[i] = new ManualResetEvent(false);             Fibonacci f = new Fibonacci(r.Next(20,40), doneEvents[i]);             fibArray[i] = f;             ThreadPool.QueueUserWorkItem(f.ThreadPoolCallback, i);         }          // Wait for all threads in pool to calculation...         WaitHandle.WaitAll(doneEvents);         Console.WriteLine('All calculations are complete.');          // Display the results...         for (int i= 0; i<FibonacciCalculations; i++)         {             Fibonacci f = fibArray[i];             Console.WriteLine('Fibonacci({0}) = {1}', f.N, f.FibOfN);         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 161k
  • Answers 161k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Eric Lippert had a fabulous post on mutating readonly structs… May 12, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer What I have done is as follows... Created a static… May 12, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer No, that's not possible. You can specify the margin, padding… May 12, 2026 at 11:54 am

Related Questions

I have a python GUI app that uses a long running function from a
I recently asked a question about functional programming, and received (good!) answers that prompted
I have an IE BHO that's in development in C#. It is supposed to
I'm looking for a simple, sample snippet of C# code to monitor an Oracle

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.