I have been trying to use thread pooling on image filtering where the method takes out the red color from an image and returns the filtered image. I get an error when y variable reaches the max amount. I have been looking for answers but couldn't find anything related to this.
public Color[,] Apply(Color[,] input)
{
int width = input.GetLength(0);
int height = input.GetLength(1);
Color[,] result = new Color[width, height];
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
ThreadPool.QueueUserWorkItem(state => Work(x, y));
}
}
void Work(int x, int y)
{
var p = input[x, y];
result[x, y] = Color.FromArgb(p.A, 0, p.G, p.B);
}
return result;
}