Parallel.For вывести значение итерации - C#
Формулировка задачи:
Подскажите, каким образом можно узнать сколько элементов обработано в конструкции
Хочется увидеть в консоли, сколько элементов осталось в обработке или хотя бы какую-то информацию о проделанной работе.
public static string S1 = "";
static void Main(string[] args)
{
string[] array = new string[] {"1", "2", "3" ... "1000"};
Parallel.For(0, array.Length, index =>
{
method1(array[index]);
});
}
public static void method1(string x)
{
s1 += x + "\r\n";
}Решение задачи: «Parallel.For вывести значение итерации»
textual
Листинг программы
public static string S1 = "";
public static int counter = 0;
static void Main(string[] args)
{
string[] array = new string[] {"1", "2", "3" ... "1000"};
counter = array.Length;
Parallel.For(0, array.Length, index =>
{
Console.WriteLine(counter);
method1(array[index]);
});
}
public static void method1(string x)
{
counter--;
s1 += x + "\r\n";
}