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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:28:50+00:00 2026-06-12T22:28:50+00:00

How do you start multiple HttpClient.GetAsync() requests at once, and handle them each as

  • 0

How do you start multiple HttpClient.GetAsync() requests at once, and handle them each as soon as their respective responses come back? First what I tried is:

var response1 = await client.GetAsync("http://example.com/");
var response2 = await client.GetAsync("http://stackoverflow.com/");
HandleExample(response1);
HandleStackoverflow(response2);

But of course it’s still sequential. So then I tried starting them both at once:

var task1 = client.GetAsync("http://example.com/");
var task2 = client.GetAsync("http://stackoverflow.com/");
HandleExample(await task1);
HandleStackoverflow(await task2);

Now the tasks are started at the same time, which is good, but of course the code still has to wait for one after the other.

What I want is to be able to handle the “example.com” response as soon as it comes in, and the “stackoverflow.com” response as soon as it comes in.

I could put the two tasks in an array an use Task.WaitAny() in a loop, checking which one finished and call the appropriate handler, but then … how is that better than just regular old callbacks? Or is this not really an intended use case for async/await? If not, how would I use HttpClient.GetAsync() with callbacks?

To clarify — the behaviour I’m after is something like this pseudo-code:

client.GetAsyncWithCallback("http://example.com/", HandleExample);
client.GetAsyncWithCallback("http://stackoverflow.com/", HandleStackoverflow);
  • 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-12T22:28:51+00:00Added an answer on June 12, 2026 at 10:28 pm

    You can use ContinueWith and WhenAll to await one new Task, task1 and task2 will be executed in parallel

    var task1 = client.GetAsync("http://example.com/")
                      .ContinueWith(t => HandleExample(t.Result));
    
    var task2 = client.GetAsync("http://stackoverflow.com/")
                      .ContinueWith(t => HandleStackoverflow(t.Result));
    
    var results = await Task.WhenAll(new[] { task1, task2 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to start multiple HTTP requests rapidly after each other, without having to
I often start multiple vim processes, how can i share the register among them?
In my method I start multiple threads and then wait until they finish their
I am using start and end dates over multiple forms, but these properties are
If you wanted to start a 'website' that could be accessible from multiple 'endpoints'.
I'm about to start building a tumblr clone that handles multiple users (so premade
If I have multiple textboxes which have different ID's but all id's start with
I'll start by quoting google's blog Project owners can now create multiple repositories for
I have an object (Client * client) which starts multiple threads to handle various
I tried using this code to start multiple Activities from a parent activity: for

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.