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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:05:33+00:00 2026-05-12T19:05:33+00:00

I have a page that needs to combine data from four different webrequests into

  • 0

I have a page that needs to combine data from four different webrequests into a single list of items. Currently, I’m running these sequentially, appending to a single list, then binding that list to my repeater.

However, I would like to be able to call these four webrequests asynchronously so that they can run simultaneously and save load time. Unfortunately, all the async tutorials and articles I’ve seen deal with a single request, using the finished handler to continue processing.

How can I perform the four (this might even increase!) simultaneously, keeping in mind that each result has to be fed into a single list?

many thanks!

EDIT: simplified example of what i’m doing:

var itm1 = Serialize(GetItems(url1));
list.AddRange(itm1);
var itm2 = Serialize(GetItems(url2));
list.AddRange(itm2); 

string GetItems(string url)
{
     var webRequest = WebRequest.Create(url) as HttpWebRequest;
     var response = webRequest.GetResponse() as HttpWebResponse;

     string retval;
     using (var sr = new StreamReader(response.GetResponseStream()))
     { retval = sr.ReadToEnd(); }
     return retval;
} 
  • 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-12T19:05:34+00:00Added an answer on May 12, 2026 at 7:05 pm

    This should be really simple since your final data depends on the result of all the four requests.

    What you can do is create 4 async delegates each pointing to the appropriate web method. Do a BeginInvoke on all of them. And then use a WaitHandle to wait for all. There is no need to use call backs, in your case, as you do not want to continue while the web methods are being processed, but rather wait till all web methods finish execution.

    Only after all web methods are executed, will the code after the wait statement execute. Here you can combine the 4 results.

    Here’s a sample code I developed for you:

    class Program
        {
            delegate string DelegateCallWebMethod(string arg1, string arg2);
    
            static void Main(string[] args)
            {
                // Create a delegate list to point to the 4 web methods
                // If the web methods have different signatures you can put them in a common method and call web methods from within
                // If that is not possible you can have an List of DelegateCallWebMethod
                DelegateCallWebMethod del = new DelegateCallWebMethod(CallWebMethod);
    
                // Create list of IAsyncResults and WaitHandles
                List<IAsyncResult> results = new List<IAsyncResult>();
                List<WaitHandle> waitHandles = new List<WaitHandle>();
    
                // Call the web methods asynchronously and store the results and waithandles for future use
                for (int counter = 0; counter < 4; )
                {
                    IAsyncResult result = del.BeginInvoke("Method ", (++counter).ToString(), null, null);
                    results.Add(result);
                    waitHandles.Add(result.AsyncWaitHandle);
                }
    
                // Make sure that further processing is halted until all the web methods are executed
                WaitHandle.WaitAll(waitHandles.ToArray());
    
                // Get the web response
                string webResponse = String.Empty;
                foreach (IAsyncResult result in results)
                {
                    DelegateCallWebMethod invokedDel = (result as AsyncResult).AsyncDelegate as DelegateCallWebMethod;
                    webResponse += invokedDel.EndInvoke(result);
                }
            }
    
    
            // Web method or a class method that sends web requests
            public static string CallWebMethod(string arg1, string arg2)
            {
                // Code that calls the web method and returns the result
    
                return arg1 + " " + arg2 + " called\n";
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login.jsp page which contains a login form. Once logged in the
I have a project that adds elements to an AutoCad drawing. I noticed that
I have a script that appends some rows to a table. One of the
I have a new web app that is packaged as a WAR as part
I have found this example on StackOverflow: var people = new List<Person> { new
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I have a snippet to create a 'Like' button for our news site: <iframe
i have a input tag which is non editable, but some times i need
Let say I have the following desire, to simplify the IConvertible's to allow me
I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME

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.