.NET 4.x Распараллеливание. Parallel.ForEach - C#
Формулировка задачи:
На данный момент выполняется такой код:
Класс LectionPanel наследуется от TreeViewItem.
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);
}Вопрос: Как распараллелить код
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);
}