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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:27:48+00:00 2026-05-30T20:27:48+00:00

I am working on an ASP.Net MVC 3 C# project. I have read about

  • 0

I am working on an ASP.Net MVC 3 C# project.

I have read about ThreadPool.QueueUserWorkItem and Tasks, I think what i need should use one of them.

public static void ProcessDay(DateTime day) { ... }

Let’s say that I want to process days from 2012-01-01 to 2012-01-31, So I have to call ProcessDay function 31 times.

How to to process 5 days at once, and keep running more threads as any of the 5 threads is done, till it finishes the 31 days?

Samples are highly appreciated, and considering showing progress bar is a good idea 🙂

  • 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-30T20:27:49+00:00Added an answer on May 30, 2026 at 8:27 pm

    A simple parallelization of this could be:-

    var dates = Enumerable.Range(1, DateTime.DaysInMonth(year, month)).Select(day => new DateTime(year, month, day));    
    Parallel.ForEach(dates, date => { ... });
    

    (Note that, if you have shared state that each thread needs to modify, then you will have to use thread synchronization techniques appropriately.)

    As for the number of threads, it’s usually best to leave Parallel.ForEach() to work this out for itself. It will use the thread pool internally and will use all available processors efficiently. You can limit the number of threads it will use by using an overload of ForEach which takes a ParallelOptions object with MaxDegreeOfParallelism set to the required amount, but you should run some benchmarks to see whether you can really achieve better results by doing this.

    Moreover, if this is a ‘long running task’ for which you wish to show progress, then you won’t be able to achieve this with a single web request. The notion of a ‘progress bar’ in a website is rather different to that in a desktop application. In a website this typically has to be done by polling. I.e. send a request which starts the process (response returned immediately), poll periodically for progress (which can be displayed in a progress bar or similar) and then display the result when finished.

    There are also frameworks and techniques being developed for ‘push’ type notification e.g. SignalR, so this may also be an option if you want to investigate it.

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

Sidebar

Related Questions

background:Me and my coworkers are working on asp.net mvc project ... we have a
I'm working in an ASP.NET MVC project where I have created a two LinqToSQL
I'm working on an asp.net-mvc project. I have an Items table and a Tags
I am working on a ASP .NET mVC project & i have to change
I am currently working on a ASP.NET MVC 3 project in which I have
I am currently working on a ASP.NET MVC 3 project in which I need
I am working on an ASP.NET MVC Project and I have a number of
I have been working on a ASP.NET MVC 2 project and i've been thinking
I'm working on an ASP.Net MVC project and have been learning a few little
I'm currently working on an ASP.NET MVC project using NHibernate and I need to

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.