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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:54:48+00:00 2026-05-13T12:54:48+00:00

Currently I’m in the process of designing the messaging system for my application (which

  • 0

Currently I’m in the process of designing the messaging system for my application (which uses AMQP on the backend via RabbitMQ). There are going to be multiple instances where a method can get data from multiple sources at the same time (ie. doesn’t have to be sequential queries).

Originally, I was going to use the ThreadPool and QueueUserWorkItem for each different request in the method, and then join them up somehow. This may be problematic, because several different components of the application can do this at once, and each component could have a large number of parallel requests which would starve the ThreadPool.

Is there a more efficient/effective way of doing this?

  • 1 1 Answer
  • 1 View
  • 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-13T12:54:49+00:00Added an answer on May 13, 2026 at 12:54 pm

    It’s ok to stress the threadpool. You can throw a bunch of workitems on it – hundreds, thousands – and just let ‘er rip. Not sure what you mean by “starve”. Unless there is a set of work items that ought to be prioritized differently, you probably don’t need to worry about starvation.

    If you use QUWI, it’s up to you to figure out how to merge the parallelized results back into one single result.


    Sounds to me like you are doing a map/reduce approach. Here’s a quick map function that uses QUWI, and an example of how to use it.

    public static IEnumerable<T2> Map_QUWI<T, T2>(List<T> inputs, Func<T, T2> fn)
    {
        int c = inputs.Count;
        if (c == 0) return null;
        T2[] result = new T2[c];
        if (c == 1)
        {
            // only one input - perform the work on main thread
            result[0] = fn(inputs[0]);
            return result;
        }
    
        using (ManualResetEvent done = new ManualResetEvent(false))
        {
            int countdown = inputs.Count;
            WaitCallback cb = delegate (Object obj)
                {
                    int ix = (int)obj;
                    result[ix] = fn(inputs[ix]);
                    if (Interlocked.Decrement(ref countdown) == 0)
                        done.Set(); // signal all done
                };
    
            // queue up all workitems
            for (int i = 0; i < c; i++)
                ThreadPool.QueueUserWorkItem(cb,i);
    
            // Wait for done.Set(), which happens in the WaitCallback
            // when the last workitem is completed.
            done.WaitOne();
        }
    
        return result;
    }
    

    Example of use:

    // returns the number of prime numbers, less than or equal to x
    private int NumberOfPrimesLessThanOrEqualTo(int x)
    {
        int count= 0;
        int n = x;
        if (n>=2) count++;
        if (x%2==0) n--;
        if (n>0)
        {
            do
            {
                if (IsPrime(n)) count++;
                n-=2;
            } while (n>0);
        }
        return count;
    }
    
    
    private void Demo()
    {
        var list = new List<int>(new int[] {2,4,8,16,32,64,128,256,512,1024,2048,
                                            4096,8192,16384,32768,65536,131072});
        Func<int,int> fn = NumberOfPrimesLessThanOrEqualTo;
        var result= Map_QUWI(list, fn);
        (new List<int>(result)).ForEach(System.Console.WriteLine);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

currently we have quite a chunky auditing system for objects within our application, the
Currently, I'm developing an application for Android OS. I would like to know the
Currently i m working on a project where there are users with four roles
Currently, I know there are several official Android styles. @android:style/Theme.Black @android:style/Theme.Light @android:style/Theme.Translucent But I
Currently I have a web service, which loads up any plugins located within its
Currently, Tapping on the same Tab (in which user is working), The App moves
Currently I have to deal with the legacy system written in VB. I'm not
Currently running this code to open Business Vision (an application written by someone else
Currently local storage for javascript is limited to cookies, which makes robust client side
Currently I'm doing some unit tests which are executed from bash. Unit tests are

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.