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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:14:27+00:00 2026-06-17T10:14:27+00:00

I am new to Parallel Programming and infact this is the first time I

  • 0

I am new to Parallel Programming and infact this is the first time I am trying it. I am currently doing a project in .NET 4 and prefer to do have 4 or 5 parallel executions.

I see some options. There is Task.Factory.StartNew Parallel.For Parallel.ForEach etc.

What I am going to do is post to a web-site and fetch the responses for about 200 URLs.

When I use Parallel.ForEach I didn’t find a way to control the number of threads and the application went using 130+ threads and the website went unresponsive 🙂

I am interested in using Task.Factory.StartNew within a for loop and divide the URLs in to 4 or 5 tasks.

List<Task> tasks = new List<Task>();
for (int i = 0; i < 5; i++)
{
    List<string> UrlForTask = GetUrlsForTask(i,5); //Lets say will return some thing like 1 of 5 of the list of URLs
    int j = i;
    var t = Task.Factory.StartNew(() =>
    {
        List<PageSummary> t = GetSummary(UrlForTask);
        Summary.AddRange(t); //Summary is a public variable
    }
    tasks.Add(t);
}

I believe that these Tasks kind of boil down to threads. So if I make Summary a List<PageSummary> will it be kind of thread safe (I understand there are issues accessing a shared variable by multiple threads)?

Is this where we should use ConcurrentQueue<T> ?

Do you know of a good resource that helps to learn about accessing and updating a shared variable by multiple tasks etc?

What is the best way I could use for this type of task as you may think ?

  • 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-17T10:14:28+00:00Added an answer on June 17, 2026 at 10:14 am

    Parallel.ForEach has overloads that take a ParallelOptions instance. The MaxDegreeOfParallelism property of that class is what you need to use.

    List<MyRequest> requests = ...;
    BlockingCollection<MyResponse> responses = ...;
    Task.Factory.StartNew(() =>
    {
        Parallel.ForEach(
            requests,
            new ParallelOptions { MaxDegreeOfParallelism = 4 },
            request => responses.Add(MyDownload(request)));
        responses.CompleteAdding();
    });
    
    foreach (var response in responses.GetConsumingEnumerable())
    {
        Console.WriteLine(response.MyMessage);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read this story on slashdot today where they announce a new parallel programming
I have the following code: Parallel.ForEach(this.listView2.CheckedItems, new ParallelOptions { MaxDegreeOfParallelism = 4 }, (CheckedItem)
Have been following this fabulous tutorial . Being new to Javascript and functional programming,
I am new to Parallel Programming. I am trying to multiply two matrices. I
I'm new to the world of parallel programming and openmp, so this may be
I'm working with the new Task Parallel Library and today went to this case:
I have a Parallel foreach function that creates a new instance of a class,
Given this code: var arrayStrings = new string[1000]; Parallel.ForEach<string>(arrayStrings, someString => { DoSomething(someString); });
I am new to parallel programming. I researched a lot about using MPI and
In my parallel programming book, I came across this code that says the slaves

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.