I am trying to update my progressbar in Parallel.ForEach, but without any success. The progressbar always gets around to 80-90 and freezes there together with the whole process. What'm I doing wrong? Can the problem be caused because the UI thread is busy with the progressbar? I would appriciate any suggestions you give me.
Here is my code:
Parallel.ForEach(test_Words, entry =>
{
Form1.fr.Invoke((Action)delegate { Form1.fr.progressBar1.Value++; });
switch (test_Type)
{
case "Definitions":
bagOfExercises.Add(Read(Definitions.get(entry.Value, entry.Key)));
break;
case "Examples":
bagOfExercises.Add(Read(Examples.get(entry.Value, entry.Key)).Replace(entry.Key, new string('_', entry.Key.Length)));
break;
}
});