Limiting the number of threads executing a method at a single time.
Posted
by Steve_
on Stack Overflow
See other posts from Stack Overflow
or by Steve_
Published on 2010-03-31T10:48:31Z
Indexed on
2010/03/31
10:53 UTC
Read the original article
Hit count: 263
We have a situation where we want to limit the number of paralell requests our application can make to its application server. We have potentially 100+ background threads running that will want to at some point make a call to the application server but only want 5 threads to be able to call SendMessage() (or whatever the method will be) at any one time. What is the best way of achieving this?
I have considered using some sort of gatekeeper object that blocks threads coming into the method until the number of threads executing in it has dropped below the threshold. Would this be a reasonable solution or am I overlooking the fact that this might be dirty/dangerous?
We are developing in C#.NET 3.5.
Thanks,
Steve
© Stack Overflow or respective owner