.


:




:

































 

 

 

 


Action, , .




public delegate void Action<in Tl, in T2>(T argl, T2 arg2)

For () Tl int, 2 ParallelLoopState. , Action , 2.

Break (), ParallelLoopState , body. Break () .

Break () , Break (). Break () . , , . , 10 , , 10 10 .

, For (), . , , . , .

Break () , For (). , , MyTransform () ParallelLoopState , Break () . , , data Main (). . IsCompleted false, data . , . ( , , : .)

// ParallelLoopResult ParallelLoopState, / Break() For() .

Using System;

Using System.Threading.Tasks;

class DemoParallelForWithLoopResult { static int[] data;

// , .

// , static void MyTransform(int i, ParallelLoopState pis) {

// , if(data[i] < 0) pis.Break();

data[i] = data[i] / 10;

if(data[i] < 1000) data[i] = 0;

if(data[i] > 1000 & data[i] < 2000) data[i] = 100; if(data[i] > 2000 & data[i] < 3000) data[i] = 200; if(data[i] > 3000) data[i] = 300;

}

static void Main() {

Console.WriteLine(" ."); data = new int[100000000];

// .

for(int i=0; i < data.Length; i++) data[i] = i;

// data, data[1000] = -10;

// .

ParallelLoopResult loopResult = Parallel.For(0, data.Length, MyTransform);

// , , if(!loopResult.IsCompleted)

Console.WriteLine("\ - , " +

" \" +

" " +

loopResult.LowestBreaklteration + ".\n");

Console.WriteLine(" .");

}

}

, , .

.





:


: 2016-12-03; !; : 416 |


:

:

,
==> ...

1676 - | 1660 -


© 2015-2024 lektsii.org - -

: 0.009 .