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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:58:48+00:00 2026-06-12T14:58:48+00:00

Hey guys this is my first attempt at using the Task libraries in 4.0

  • 0

Hey guys this is my first attempt at using the Task libraries in 4.0 so if you see anything else I’m besides my problem that is not correct please do let me know.

My problem is that when I schedule a bunch of task which inside use a webclient to make a request, the first few make it through just fine, but after a certain time my webclient starts throwing an exception. It as if it creates the webclient then sticks in the Task and waits for a thread to pick it up but by that time the timeout time is reached .. that’s just my assumption.

Here is the code :

var TmsThread = Task.Factory.StartNew(() => UpdateTmsNullPackages(), TaskCreationOptions.LongRunning);

that runs in the Form1_Load of the windows app. This is what it calls

public void UpdateTmsNullPackages()
    {
        Parallel.ForEach(TmsNullPackages, Package =>
        {
            try
            {
                Task<string> task = Task.Factory.StartNew(() => Package.GetPackageTmsId(), TaskCreationOptions.AttachedToParent);
                task.ContinueWith(t =>
                    {
                        if (!String.IsNullOrEmpty(t.Result))
                        {
                            Package.TMSID = t.Result;
                            NowTmsIdFoundPackages.Add(Package);
                        }
                    });
            }
            catch(Exception ex){}
        });
    }

which in turn, runs this

 public static string GetPackageTmsId(this TwcPackage Package)
    {
        string TMSID = null;
        if (!(String.IsNullOrEmpty(Package.movie_Provider)) && !(String.IsNullOrEmpty(Package.movie_Product)) && !(String.IsNullOrEmpty(Package.movie_Provider_ID)) && !(String.IsNullOrEmpty(Package.movie_Asset_ID)))
        {
            try
            {
                using (WebClient client = new WebClient())
                {
                    client.Credentials = new NetworkCredential(TMSID_Recheck.Properties.Settings.Default.WebRequestUser, TMSID_Recheck.Properties.Settings.Default.WebRequestProdUserPassWord);
                    XmlDocument xmlDoc = new XmlDocument();
                    string URLToBeRequested = TMSID_Recheck.Properties.Settings.Default.RequestProdBaseURL + TMSID_Recheck.Properties.Settings.Default.RequestAPIVersion + "/" + TMSID_Recheck.Properties.Settings.Default.RequestAPIProgramServiceCall + TMSID_Recheck.Properties.Settings.Default.RequestAPIProgramAssociationServiceCall + Package.movie_Provider + ':' + Package.movie_Product + ':' + Package.movie_Provider_ID + "::" + Package.movie_Asset_ID;
                    try
                    {
                        xmlDoc.LoadXml(client.DownloadString(URLToBeRequested));
                        XmlNodeList Program = xmlDoc.DocumentElement.SelectNodes("program");
                        if (Program.Count > 0) TMSID = Program[0].Attributes["TMSId"].Value.ToString();
                    }
                    catch (WebException ex)
                    {
                        if (ex.Status != WebExceptionStatus.Timeout)
                        {
                            if (((HttpWebResponse)ex.Response).StatusCode != HttpStatusCode.NotFound) {  }
                        }
                        else {  }
                    }
                }
            }
            catch (Exception ix) {  }
        }
        return TMSID;
    }

the issue happens when downloadstring is called after a couple hundred tasks it throws a timeout exception.

  • 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-12T14:58:49+00:00Added an answer on June 12, 2026 at 2:58 pm

    the issue happens when downloadstring is called after a couple hundred tasks

    And how many tasks have completed in that time slice?

    It looks like you are simply queuing too many requests. Your system and the remote server probably have policies in place to limit the number of simultaneous connections.

    The solution (and a quick diagnosis test) would be to use MaxDegreeOfParallelism in the ForEach.

    Here is a similar question with some good answers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys this should be simple, I'm just not seeing it, I would like
hey guys having this really simple problem but cant seem to figure out have
Hey guys I simply cannot get this to work. I have some content that
Hey guys I'm not sure how to write this in AS3, but basically I
Hey guys, this is my first time actually posting at stackflow but i've used
Hey there guys, this is my first question on Stack Overflow. I figured this
Hey guys, first off all sorry, i can't login using my yahoo provider. anyways
Hey guys, I'm currently trying to implement a function using C that takes in
Hey guys! First of all, I know this kind of stuff is quite shitty,
Hey guys. I've just published my first Android application to show this guy who

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.