views:

120

answers:

1

I have a class MyClass with a method MyMethod. For every MyClass instance in a list of MyClass instances i want to invoke MyMethod and have them run in a separate thread. I am using .NET 4.0 and the Parallel extensions.

+1  A: 
Parallel.ForEach(MyClassList, myclass => myclass.MyMethod());

Note that this won't necessarily run every invocation in a separate thread; it'll use the available thread pool to try to achieve an appropriate level of parallelism.
It is, however, the equivalent of running all of those MyMethod invocations in a big Parallel.Invoke, which appears to be what you're looking for.

tzaman