C# .NET - ThreadPool.QueueUserWorkItem(new WaitCallback(
Asked By erik little
14-Sep-06 12:29 AM
I have read about this already i would like for someone to clarify this for me...
If i queue 1 or if i queue 30 items to the thread pool my main thread goes about its business and the worker threads have no effect what so ever on the items i queue to the thread pool ???
erik
Have no effect whatsoever?
If you queue a UserWorkItem onto the pool, the next available thread in the pool begins processing it and runs whatever code you have in your callback. So, there is definitely an effect on the itmes you have queued. Yes, your main thread does go about its business, but the worker threads will do whatever business logic you have programmed for the pool.
thanks for the clear explantation
sateesh replied to Peter Bromberg
I have written a windows service which internally uses a threadpool and have used it with waitcallback and object as two parameters.
When i am trying use the service to print or view docs using the acrobatdistiller by placing them in the queue,Suddenly at one point the docs tat have to get printed are getting stuck and i am compelled to restart my windows service again and again .
Does this problem has anything to do with the threadpool class or is there any problem with the distiller i am using.
Please reply me asap if u have any confusion in this...
Peter Bromberg replied to sateesh
We'd have to see sample code. If you are kicking off your threads from the main Windows Service thread, yes it is a problem.
ThreadPool.QueueUserWorkItem only uses 2 threads Hello, I am using HttpListener to listen on a given port. When I get a request, I call: ThreadPool.QueueUserWorkItem(new WaitCallback (ProcessRequest), context); to service the request in a new thread. I have put some print looks like only 2 threads get used. I have tried various values for: System.Threading.ThreadPool.SetMaxThreads(x, y); System.Threading.ThreadPool.SetMinThreads(x2, y2); and I always get two threads as being used even though the
ThreadPool.QueueUserWorkItem .NET Framework Hi, I'm looking to build an application that fires off a number started etc). This class will manage the state for the process it encapsulates. I use ThreadPool.QueueUserWorkItem to call Start on each of my process wrapper classes which in turn calls start is if I hook up to some events that my wrapper class raises during the WaitCallback does this stop the worker thread being returned to the thread pool? Lets say after of the events I want to know about this and act accordingly. .NET Framework Discussions ThreadPool.QueueUserWorkItem (1) QueueUserWorkItem (1) OnProcessStateChangedHandler (1) EventHandler (1) WaitCallback (1) ThreadPool (1) EventArgs (1) Process.Start (1) It
ThreadPool question .NET 2 .NET Framework I have several Threads that start other Threads like this: ThreadA { for (int i = 0; i <10; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(TestThread1), (object)i); } / / Wait for all TestThread1 to terminate before proceeding ?????? } ThreadB { for (int i 0; i <10; i++) { ThreadPool.QueueUserWorkItem(new WaitCallback(TestThread2), (object)i); } / / Wait for all TestThread2 to terminate before proceeding ?????? } - -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - The TestThread1 and TestThead2 sleep up to 30 seconds before terminating. How can I tell when all the ThreadA ThreadPool requests have completed ? thanks B C# Discussions ThreadPool.QueueUserWorkItem (1) QueueUserWorkItem (1) AutoResetEvent (1) WaitCallback
ThreadPool.QueueUserWorkItem memory problem .NET Framework Hi, When I run the simple Console application below, the memory keeps climbing. Is there a way to use the ThreadPool and avoid this memory problem ? thanks, Brian using System; using System.Text; using System.Threading static void Main(string[] args) { for (int i = 0; i> = 0; i++) { Thread.Sleep(0); ThreadPool.QueueUserWorkItem(new WaitCallback(sayHello)); } } public static void sayHello(Object o) { Console.WriteLine("hello"); } } } C# Discussions ThreadPool.QueueUserWorkItem (1) QueueUserWorkItem (1) Console.WriteLine (1) SetMaxThreads (1) GetMaxThreads (1) WaitCallback (1) On Mar 2