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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:49:05+00:00 2026-05-13T14:49:05+00:00

I have an ASP.NET MVC web application that makes REST style web service calls

  • 0

I have an ASP.NET MVC web application that makes REST style web service calls to other servers. I have a scenario where I am making two HttpWebRequest calls to two separate services. I need them both to complete to continue, but their order doesn’t matter. They may take 1-2 seconds each and I am running them in sequence now. Running them in parallel would decrease the user response time, but what is the best way?

In researching this, I can think of several options:

  • Execute one request on the main thread, and spin up a second thread for the other request. Should created new threads or use a thread pool? If I use a pool, how do I size it? Also, not sure how I can join the threads back together (e.g. use ThreadPool.RegisterWaitForSingleObject)?
  • Try and leverage the built-in IAsyncResult support for one or both of the requests. Again, not sure on which threads the async request execute, so not sure how to size the thread pool. How do I join IAsyncResult back into my main thread? All the examples I find process information in the callback, but I can just wait in my main thread and use the IsCompleted property?

I need to find a solution that will both function, and perform at scale. That is why I am worried about thread pool sizing. I would hate to have requests blocking because they are waiting for available threads.

  • 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-13T14:49:05+00:00Added an answer on May 13, 2026 at 2:49 pm

    One of the answers to Multithreading WebRequests, a good and stable approach? : CSharp uses a ManualResetEvent event = new ManualResetEvent(), a reference counter equaling the number of in flight requests and Interlocked.Decrement to control the event.Set(). The main thread then waits by calling event.WaitOne().

    However, WaitHandles – Auto/ManualResetEvent and Mutex mentions that ManualResetEvent “can be significantly slower than using the various Monitor methods” like Wait, Pulse and PulseAll.

    I ended up basing my code off of this Noah Blumenthal blog post: Run generic tasks async (fluent-ly). I did make two changes: implement IDisposable and call .Close() on the ManualResetEvent and switch from using a lock() to Interlocked .Increment() and .Decrement().

    public class AsyncQueueManager : IDisposable {
        private readonly ManualResetEvent waitHandle = new ManualResetEvent(true);
        private int count = 0;
    
        public AsyncQueueManager Queue(Action<object> action) {
            Interlocked.Increment(ref count);
            waitHandle.Reset();
            Action<object> actionWrapper = CreateActionWrapper(action);
            WaitCallback waitCallback = new WaitCallback(actionWrapper);
            ThreadPool.QueueUserWorkItem(waitCallback);
            return this;
        }
    
        private Action<object> CreateActionWrapper(Action<object> action) {
            Action<object> actionWrapper = (object state) =>
            {
                try {
                    action(state);
                } catch (Exception ex) {
                    // log
                } finally {
                    if (Interlocked.Decrement(ref count) == 0) {
                        waitHandle.Set();
                    }
                }
            };
            return actionWrapper;
        }
    
        public void Wait() {
            waitHandle.WaitOne();
        }
        public void Wait(TimeSpan timeout) {
            waitHandle.WaitOne(timeout);
        }
    
        public void Dispose() {
            waitHandle.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My team is writing a content-managed web-hosting application in ASP.Net MVC 2 with the
I have a web application that launches as second web application in a new
I'm trying to make a MVC 2 web application for a small portal. I
in my asp.net mvc project i added facebook authentication to my project. I also
I'm creating an Intranet site in ASP.NET MVC 3 Beta and would like to
I am trying to create an application that uses <authorization> rules to limit the
I'm trying to add dynamic content to my mvc application. I'm using Steven Sanderson
MVC frameworks in general? Is it different from MVC in desktop GUI applications? What
I installed Visual Studio 2010 SP1 the other day and now when i try
Let me first apologise for the length of the entire topic. It will be

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.