I'm having a really hard time working this out.
The code is supposed to import images from a file dialog. And each image is supposed to be processed and sent to class correct. Processor is a class that detects shapes, so basically I am sending every image and detecting shapes in it(filtered to a certain criteria within the class processor)
newList will get the centers of all the shapes in an image.
I have little knowledge in Parallelism and I can't seem to figure how to work this out. Keep in mind that I do not need to pass anything from one iteration to another. I just want images to be processed and corrected each at a time, with the entire operation divided to threads.
I have every iteration a stand alone one and I need not return anything from one iteration to another.
Currently the problem is that the results returned from class correct are sometimes incorrect. i guess it is because processor and newList must also be local? If yes how can I solve this? If not where have I gone wrong?
Also keep in mind that using a normal foreach works just fine
Here is my code:
Parallel.ForEach(ofd.FileNames,
(file) =>
{
Image exam = Image.FromFile(file);
var cvImage = new Image<Bgr, byte>((Bitmap)exam);
processor = processorMain;
processor.ProcessImage(cvImage);
List<Point> newList = new List<Point>();
newList = processor.getList();
correct.correct(cvImage, answerKey, nOptions);
});