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
2010-06-06 16:07:08