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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:01:22+00:00 2026-05-26T02:01:22+00:00

This is just an imaginary problem, I’m hoping that the solution will help in

  • 0

This is just an imaginary problem, I’m hoping that the solution will help in whole range of similar scenarios. Suppose I need to count total size of all external resources on a webpage (images, scripts etc.). I download the page, extract all SRC information and transform the URL list into download tasks:

async Task<int> GetTotalSize(Uri uri) {
  string[] urls = ... code to extract all external resources' URLs from given page ...

  var tasks = from url in urls.Distinct()
                select new WebClient().DownloadDataTaskAsync(new Uri(url));
  var files = await TaskEx.WhenAll(tasks);
  return files.Sum(file => file.Length);
}

Now, if one of the links is unreachable for any reason, the whole TaskEx.WhenAll is aborted with WebException. What I need is to ignore any WebExceptions inside individual tasks and assume length of 0 in that case. Any ideas?

  • 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-26T02:01:23+00:00Added an answer on May 26, 2026 at 2:01 am

    Just add a separate (asynchronous) method to get the size of a single url. Then add them up.

    e.g.,

    static async Task<int> GetTotalSizeAsync(params string[] urls)
    {
        if (urls == null)
            return 0;
        var tasks = urls.Select(GetSizeAsync);
        var sizes = await TaskEx.WhenAll(tasks);
        return sizes.Sum();
    }
    
    static async Task<int> GetSizeAsync(string url)
    {
        try
        {
            var str = await new WebClient().DownloadStringTaskAsync(url);
            return str.Length;
        }
        catch (WebException)
        {
            return 0;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This just won't work. The problem is that I do not know enough to
I'm hoping this just needs a new pair of eyes casting over it. I
I don't think that this could be done in C#, but posting this just
How do I setup a class that represents an interface? Is this just an
It looks like this just sends a ping, but whats the point of that
I just found that not only does this code compile, it seems to split
This just started happening three weeks or so ago. The content of my website
This just saves time. Since I already have a web applciation. I can just
Ok, I've got a list like this (just a sample of data): data =
So Python has positive and negative infinity: float(inf), float(-inf) This just seems like the

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.