我试图打印多个PDF字节数组。由于我需要使用户能够同时打印多个报告的功能,因此我正在使用Parallel foreach。函数通过第一个字节数组,但在第二个Dequeue中,我得到了“集合在枚举器实例化后被修改”。错误。我如何解决这个问题,同时仍然允许用户同时打印?集合在枚举器实例化后被修改错误
下面的代码:
public static void PrintingQueue(Queue<byte[]> printQueue, string printer, int copies)
{
Parallel.ForEach(printQueue, (currentFile) =>
{
var printFile = printQueue.Dequeue();
PrintWithGSPrint(printFile, printer, copies);
});
}