Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

ThreadPool

Hi,

Im using the threadpool in vb.net but am having a problem with it. I set the SetMaxThreads to 1 because i only want 1 thread to execute at a time. You may wonder why use threads then at all, but I am using the threadpool because i put a certain function in it that i want executed one at a time but if there is more than 1 thread using the function i want the 1 to execute as quickly as the other 1 ends.

the problem im having is that i can add lots of threads which execute the function at a time, but at a certain stage it stops responding. it is as if the threadpool becomes full and does not want to take anymore threads. when i check the worker threads using GetAvailableThreads it says 0.

this is my first time using the threadpool so i am not sure if i have to release a worker thread when it is done or how to do that. at the moment i put a thread in the threadpool like this :

ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf sockIncoming), strData)

and it executes my function 'sockIncoming' and that is all i do.

Should i release the thread at some stage or why is this happening?

thanks for any help
[1197 byte] By [driesie] at [2007-11-11 7:54:36]
# 1 Re: ThreadPool
Threadpool is not very safe. Callbacks may be terminated to save system resources.

You should maintain your own Queue with objects that you can execute and then read from this Queue with a normal Thread.
etoostr at 2007-11-11 21:48:18 >