For nested in parallel

1

I am trying to rotate two% nested%. The second would like it to be parallel. Follow my code.

for (int i = 0; i < original.Width; i++)
    {
        Parallel.For(0, original.Height, j =>
        {
            Color originalColor = original.GetPixel(i, j);
            Color CorEmNegativo = Color.FromArgb(255 - originalColor.R, 255 - originalColor.G, 255 - originalColor.B);
            alterado.SetPixel(i, j, CorEmNegativo);
            Thread.Sleep(100);
        });
    }

The following error is returning to me: for How can I do this?

    
asked by anonymous 02.12.2016 / 13:26

1 answer

1

I had to do the following, and it worked:

for (int i = 0; i < original.Width; i++)
{
    Parallel.For(0, original.Height, j =>
     {
        lock (alterado)
        {
             Color originalColor = original.GetPixel(i, j);
             Color CorEmNegativo = Color.FromArgb(255 - originalColor.R, 255 - originalColor.G, 255 - originalColor.B);
             alterado.SetPixel(i, j, CorEmNegativo);
        }
    });
}
    
02.12.2016 / 13:59