2

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.

kjv
  • 11,047
  • 34
  • 101
  • 140

1 Answers1

5
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
  • 46,925
  • 11
  • 90
  • 115