I'm trying to print multiple PDF byte arrays. Since I need the functionality to allow users to be able to print multiple reports simultaneously, I'm using a Parallel foreach. The function gets through the first byte array fine, but on the second Dequeue I get the "Collection was modified after the enumerator was instantiated." error. How do I fix this while still allowing the users to print simultaneously?
Here's the code:
public static void PrintingQueue(Queue<byte[]> printQueue, string printer, int copies)
{
Parallel.ForEach(printQueue, (currentFile) =>
{
var printFile = printQueue.Dequeue();
PrintWithGSPrint(printFile, printer, copies);
});
}