mEt

In my application I restrict MaxThreads on the ThreadPool to 2. This works properly on WinXP Pentium 4 3.0 Ghz and WinXP w/ a AMD Opteron 165 Dual Core. I copied my program up to the server which is running Windows 2003 Server w/ Dual - Dual Core Xeon's (4 cores total).

Code Block


ThreadPool.SetMaxThreads(2,2);


ThreadPool.QueueUserWorkItem(new WaitCallback(convertVideo), file);


// New thread creates instance of ffmpeg.exe and converts the video.



On my Windows XP machine never any more than 2 ffmpeg instances are started but on the server it starts 4 and loads all the cores up. Any thoughts Thanks in advance.



Re: Visual C# General Restricting Number of Threads - Win 2003 Serv.

mEt

I just saw on
http://msdn2.microsoft.com/en-us/library/system.threading.threadpool.setmaxthreads.aspx
that you cannot set the number of worker threads lower than the number of processors on the machine. Does it consider each separate core as a processor

If so, does anyone have a recommended method to restrict the number of threads I have going




Re: Visual C# General Restricting Number of Threads - Win 2003 Serv.

Peter Ritchie

Yes, each core is a processor.

Why do you want to use a thread pool if you don't want to use the most possible threads






Re: Visual C# General Restricting Number of Threads - Win 2003 Serv.

mEt

Well the program monitors a folder that videos are inserted into. This could be any number of videos and from there it converts the videos to a specified format and deletes the original videos.

I just wanted to be able to convert multiple videos at any given time and I figured this would be an easy way to handle the task. What method would you recommend taking




Re: Visual C# General Restricting Number of Threads - Win 2003 Serv.

Peter Ritchie

If what you want to perform on a background thread isn't very quick (more than a few hundred milliseconds) thread pool threads aren't ideal for this. Thread pool threads are shared between the application and the runtime, if you're hogging too many thread pool threads you run the risk of causing the runtime (and thus, your application) problems. If you lower the number of thread pool threads below the default you're affecting the ability of the runtime to do what it needs to do...

If you're looking to utilize the multiple processors I would simply just create one thread per processor (see Environment.ProcessorCount) and manage how many threads are active and queued.

The thread pool sounds like it would do what you want, in this case, but it doesn't. It can be running many more threads and processors/cores and if there are more cpu-bound threads than cpus then you'll actually make your application slower, not faster.