Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Asynchronous code

Status
Not open for further replies.

Badgers

Programmer
Nov 20, 2001
187
US
Hi,

I have an interesting problem.

I am using ThreadPool.QueueUserWorkItem to fire off a number of async threads.

What I want to do is set a ceiling of threads to run, say for example 3.

As each thread complets - I need to keep a counter of the threads completed, and using the WaitHandle.WaitAny method fire off a new thread immedialty.

I am getting troublesome results, any help or code samples would be appriciated.

I have seen the threadpool.setmaxthreads but want to acheive the same thing manually.

Thanks

Tim.
 
I am getting troublesome results, any help or code samples would be appriciated.
we need details. the statement above tells us nothing.
What I want to do is set a ceiling of threads to run, say for example 3.

As each thread complets - I need to keep a counter of the threads completed, and using the WaitHandle.WaitAny method fire off a new thread immedialty.
I have seen the threadpool.setmaxthreads but want to acheive the same thing manually.
if the functionality is built in, why code it manually?

I have some limited exposure with ThreadPool.QueueUserWorkItem. I have only used this in trivial thick client applications though, not the web. For asynchronous web or non-trivial thick clients I have used a Messaging Service Bus to handle the asynchronous commands.

I would look into the source of NServiceBus, Mass Transit and/or Rhino.ServiceBus to see how they handle threading. I know Rhino.ServiceBus handles threads manually. I'm not sure about NServiceBus or MT.

I also posted a FAQ on asynchronous desktops apps which utilizes ThreadPool.QueueUserWorkItem. A link to the article is posted in my signature. I'm not sure it would help in your current situation as the example doesn't manage the number of threads.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top