PrintManager threading issue

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all!
I have a method that prints several sheets in a loop, using Document.PrintManager.
If I am on a slow computer (like my own), everything works well. If i am on a fast computer however, things get all wrong and I wonder if anyone could help me?
The problem: Sheets gets the name of the next sheet, causing printing errors and file-in-use errors.
I'm suspecting the following:
In a loop, the settings and parameters for the PrintManager is set and defined, and the PrintManager submits the print. I believe this starts a new thread, and the loop starts over. Before the printing thread is done printing, the PrintManager is defined again in the main thread, messing up the Print.
Pseudocode:
public void PrintSheets(Document doc, PrintSettings settings, List<ViewSheet> sheets) { foreach(var sheet in sheets) { var printManager = GetPrintManager(doc, settings, sheet); //sets up print manager and returns it printManager.SubmitPrint(); } }
The reason i believe this is a threading issue is because if i let the working (gui) thread sleep at at every iteration of the loop, the method works as intended:
public void PrintSheets(Document doc, PrintSettings settings, List<ViewSheet> sheets) { foreach(var sheet in sheets) { var printManager = GetPrintManager(doc, settings, sheet); //sets up print manager and returns it printManager.SubmitPrint();
Thread.Sleep(5000); } }
I have a virtual printer that bypasses the SaveAs dialog by the way.
Regards,
Eirik