Meya-awe said:
Jon, appreciate your quick response. I have read this response in the
MSDN documentation for "threadpool" as well. But to put it politely, to
say that "it was not designed for this" is not a conviencing answer,
why? what was it designed for?
Short tasks which aren't going to clog it up. There are only 25 threads
(per processor) in the thread pool. If 25 different things decided to
add long-running tasks, there wouldn't be any threads left to run the
short-running tasks.
Besides that, the point of a thread pool is to avoid the cost of
creating a new thread. IF the thread is going to run for a long time,
the cost is pretty insignificant in the long run. With the typical use
of a thread pool, the time spent creating a new thread may even exceed
the time spent running the specified delegate.
The problem with new Thread is that it does not support passing data to
the thread and one needs to use the threadpool since one can pass the
data inside an developer defined object.
That's not a good reason to use the thread pool IMO. There are other
ways to get round that. See
http://www.pobox.com/~skeet/csharp/threads/parameters.shtml
with respect to the expiration, it looks like i pushed the "Send" button
soon. I was refering to the WaitOne method call which has an expiration.
But was running multiple threads in my brain and lost synchronization
.
I'm still not entirely sure I know what you're after here, but using
separate (non-threadpool) threads, you'd probably want to use
Thread.Join.
In any case, it looks like i can call the QueueUsersItem multiple times
and relay on some CLR or OS mechanism to queue my requests or exactly
what happens here?
The thread pool will queue requests if it doesn't have enough threads
available. However, if you really *do* want to use a thread pool, I'd
suggest using a custom-built one rather than the system one. It's very
hard to predict what other methods use the system thread pool, and you
can easily end up with a deadlock which is very hard to diagnose. I
have a thread pool you can use:
http://www.pobox.com/~skeet/csharp/miscutil