1
I’m trying to spin two for
nested. The second would like it to be parallel. It follows 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: O objeto está sendo usado em outro lugar.
How can I do ?
Which is the line of error?
– Jéf Bueno
I don’t think that’s gonna happen... The error is already saying, the (original) object is already being used in another process, as you are running the for in parallel, more than one thread is accessing the same object simultaneously, apparently there is a protection against it.
– FBatista
Probably the problem should be with the variable changed. You can try using this:
lock(alterado) { alterado.SetPixel(i, j, CorEmNegativo); }
– Ricardo Pontual
Same @Ricardopunctual error occurred
– Raphael Prado de Oliveira
http://answall.com/a/169116/101
– Maniero
But it was wrong on which line???
– Ricardo Pontual
On the line of Parallel.For ...
– Raphael Prado de Oliveira
yesterday I took this test of him there using Task inside a normal For, gave the same error message, when trying to execute "original.Getpixel(i, j);"
– FBatista