.NET 4.x Распараллеливание. Parallel.ForEach - C#

Узнай цену своей работы

Формулировка задачи:

На данный момент выполняется такой код:
Hashtable files2copy;
 
 void startButton_Click(object sender, RoutedEventArgs e)
{
     files2copy = new Hashtable();
     foreach (LectionPanel lPanel in treeView.Items)
     {
        LectionCount(lPanel);
     }
}
 
private void LectionCount(LectionPanel lPanel)
        {
            if (lPanel.HasItems)
                foreach (LectionPanel childPanel in lPanel.Items)
                {
                    LectionCount(childPanel);
                }
 
            string path = lPanel.Lection.File;
 
            if(!files2copy.ContainsKey(path.GetHashCode()) && File.Exists(path))
                files2copy.Add(path.GetHashCode(), path);
        }
Класс LectionPanel наследуется от TreeViewItem.

Вопрос: Как распараллелить код

foreach (LectionPanel lPanel in treeView.Items)
     {
        LectionCount(lPanel);
     }

используя Parallel.ForEach ?

Пытался, но ничего рабочего не вышло.

Решение задачи: «.NET 4.x Распараллеливание. Parallel.ForEach»

textual
Листинг программы
if (lPanel.HasItems)
                foreach (LectionPanel childPanel in lPanel.Items)
                {
                    LectionCount(childPanel);
                }

ИИ для рефератов и докладов


  • Экспорт Word по ГОСТу
  • Минимум 80% уникальности текста
  • Поиск релевантных источников в интернете
  • Готовый документ за 2 минуты

Оцени полезность:

7   голосов , оценка 4.571 из 5
Похожие ответы