72
1
using System;
2
using System.Threading;
3
using System.Threading.Tasks;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
//ParallelLoopStateBreak();
10
ParallelLoopStateStop();
11
}
12
13
private static void ParallelLoopStateBreak()
14
{
15
var rnd = new Random();
16
int breakIndex = rnd.Next(1, 10);
17
18
Parallel.For(1, 100, (i, state) => {
19
Console.WriteLine("Beginning iteration {0}", i);
20
21
int delay;
22
lock(rnd)
23
{
24
delay = rnd.Next(1, 1000);
Cached Result