- .
int numberOfThreads = int.Parse(args[0]);
Enum.Range
IEnumerable , LINQ .
static void Main(string[] args)
{
int numberOfThreads = int.Parse(args[0]);
Task.WaitAll(
Enum.Range(0, numberOfThreads)
.Select(
Task.Factory.StartNew(() => doStuff())
)
.ToArray()
)
);
Console.WriteLine("Done !");
}
Parallel.For
, , .
static void Main(string[] args)
{
int numberOfThreads = int.Parse(args[0]);
Parallel.For(1, numberOfThreads, (i) => doStuff());
Console.WriteLine("Done !");
}
, , ParallelOptions. 100 , , .
static void Main(string[] args)
{
int numberOfThreads = int.Parse(args[0]);
Parallel.For(
1,
100,
new ParallelOptions
{
MaxDegreeOfParallelism = numberOfThreads
},
(i) => doStuff()
);
Console.WriteLine("Done !");
}