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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:20:14+00:00 2026-06-08T09:20:14+00:00

I have a C# 4 application that is subscribing for an event which I

  • 0

I have a C# 4 application that is subscribing for an event which I expect to be raised a very large number of times in quick succession. Each time it is raised a bit of work is required to be done that I don’t really want to block the event thread with.

It feels like I should pass off this “chunk” of work to a background thread / task and allow the event thread to continue, however I also need to make sure that too many threads aren’t created as, as I say, I expect this event to be raised a lot of times quickly.

Is there a recognized pattern or recommended approach for passing off event handler workload to background threads but limiting the amount of threads created?

It feels like there should be some way of using the Task Parallel Library for this, but can’t find anything that does exactly what I need at the moment.

Let me know if anyone needs any more information, as I appreciate I’ve been quite general with what I’ve said.

Thanks.

  • 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-08T09:20:17+00:00Added an answer on June 8, 2026 at 9:20 am

    If the “bit of work” that you want to perform each time the event is raised is small and mostly CPU-bound, then just start a Task each time. The ThreadPool will determine the optimal number of threads to use, which will most likely be close to the number of CPU cores you have. You don’t have to worry about limiting the degree of parallelism in this case.

    If the work for each raise can take a long time or if it’s mostly IO-bound, then you should manually limit the degree of parallelism. One way to do that would be to have a small number of threads that block if there’s no work, and otherwise process the events from a queue. You could achieve this by using BlockingCollection.

    Possibly the best option, if you can use .Net 4.5, is to use ActionBlock from TPL Dataflow with MaximumDegreeOfParallelism set. With it, you won’t waste any threads when there is no work and you can set the maximum number of threads to be used (or not).

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

Sidebar

Related Questions

I have a application that runs very well on JBoss using JSF 2. I
I have an application that is successfully deploying on tomcat, which I must migrate
I have an application that has 2 beans with the same name, but which
I have an winforms application that was built using MVC. The controller is subscribing
I have application that makes different queries with different results so the caching in
I have application that is connecting to the DB and if I enter incorrect
I have application that is up more than 3 days. I can see in
I have application that brings response via Ajax and creates 5-20 new jQuery click
I am building a Rails application that contains Developer s who have Application s.
I have an application that goes like this F5 load balancer - IHS(a&b) -

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.