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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:55:38+00:00 2026-05-20T18:55:38+00:00

List<string> urls = this.populateRequestList(); this.Logger(Starting); var reqs = urls.Select<string, WebRequest>(HttpWebRequest.Create).ToArray(); var iars = reqs.Select(req

  • 0
List<string> urls = this.populateRequestList();

this.Logger("Starting");

var reqs = urls.Select<string, WebRequest>(HttpWebRequest.Create).ToArray();
var iars = reqs.Select(req => req.BeginGetResponse(null, null)).ToArray();
var rsps = reqs.Select((req, i) => req.EndGetResponse(iars[i])).ToArray();

this.Logger("Done"); 

Things I noticed so far:
When I run this code, “Starting” shows up in my log, but “Done” never shows up. When I view the whole process in the debugger, it seems to skip over it like it’s not even there. No exceptions are being thrown either. When reqs.Select is looping through req.EndGetResponse(iars[i]), it’s like it freezes or skips over stuff. When I view it in the debugger, I don’t get past 10-15 loops before it just skips to the end.

Questions:
How do I stop this from “skipping” sometime during var rsps = reqs.Select((req, i) => req.EndGetResponse(iars[i])).ToArray();?

How to I get the html from rsps? I think this problem doing that stems from the “skipping”. I tried looping through each response and calling Repsponse.GetResponseStream() etc…, but nothing happens as soon as it skips.

  • 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-20T18:55:39+00:00Added an answer on May 20, 2026 at 6:55 pm

    The problem with your code is that BeginGetResponse(null, null) accepts a callback as the first argument which is invoked when the operation completes. This callback is where EndGetResponse should be called. When you call EndGetResponse, the operations are not yet completed.

    Look at this article to see how aync web requests can be made in C# using iterators: http://tomasp.net/blog/csharp-async.aspx.

    If using the task parallel library or .NET 4 you can also do this:

    var urls = new List<string>();
    
                var tasks = urls.Select(url =>
                    {
                        var request = WebRequest.Create(url);
                        var task = Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
                        task.Start();
                        return task;
                    }).ToArray();
    
                Task.WaitAll(tasks);
    
                foreach (var task in tasks)
                {
                    using (var response = task.Result)
                    using (var stream = response.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var html = reader.ReadToEnd();
                    }                                
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation like this. I have a list of urls in a
The following asynchronous C# code runs through a list of 7 URLs and tries
The following line is supposed to print a list item which is a variable
This just might be too easy for all of you, but I am just
There's already a lot of blog posts out there about being able to hook
I'm writing a small networking program in C++. Among other things it has to
I've got somthing to parse with Gson, but Gson recognize only json object and
I'm trying to make a utility httpClient class My code works great the first
I'm a C# developer for Windows and I know NOT THAT MUCH about web
I'm rendering a collection of checkboxes (over 20) onto an MVC 3 Razor view

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.