views:

226

answers:

3

I'm currently using the Paralle Extensions that are part of Reactive Extensions for .Net(Rx). I believe they are also available through .Net 4 beta releases.

1) Is there any way to determine how many threads are actualyl being utilized. I assume this is related to Environment.ProcessorCount (# of logical cores) but I want to check this.

2) Is there any way of configuraing how many thread you wish to use? I noticed there is a ParallelOptions.MaxDegreeOfParallelism property that looks promising but it appears to default to -1 (no limit to the number of threads) and I'm also not quite sure if this can be set once for the current application, as oposed to beign passed in to each call to Parallel.For(), etc.

Thanks.

A: 

I dunno about .Net 4.0, but in PFX June 2008 CTP there is System.Threading.Tasks.TaskManagerPolicy class, which I'm using to limit used processors count. There are lots of examples on how to use it, just google it. :)

Vasiliy Borovyak
A: 

There is the Observable.Context object, that defines how parallel stuff is done inside the Rx Threads. The default implementation uses the global::System.Threading.ThreadPool.QueueUserWorkItem feature. so you can set there the MaxWorkerThreads to define a maximum.

read more on the rx team blog. http://blogs.msdn.com/rxteam/archive/2009/11/21/observable-context-observable-subscribeon-and-observable-observeon.aspx

hope this helps.

cRichter
A: 

UPDATE: This option appeared in .Net 4; ParallelOptions.MaxDegreeOfParallelism


In answer to my own question, the answer appears to simply be - No. The number of threads/cores used doesn't appear to be configurable.

locster