Reputation: 2381
I am not sure if this is to with a threading issue or not.
I am printing labels to a standard windows printer. The label is drawn in GDI and then passed to another object which prints it on a background thread.
I am using a BackgroundWorker for this process. LabelPrinter.Print(Label as PrintLabel)
starts the backgroundWorker and passes the label details to it. The PrintPage eventhandler renders the page and sends it to the printer.
The issue is, users occasionally get an error stating:
System.Drawing.Printing.InvalidPrinterException: Settings to access printer '\\printserver\label' are not valid.
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal()
at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings pageSettings)
at System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.StandardPrintController.OnStartPrint(PrintDocument document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
Users only get this occasionally, although I am informed it is worse when there print multiple labels in succession (few minutes between labels). They will be able to print labels all day, when they will suddenly hit this error and get it 4 or 5 times, then the problem will go usually go away.
Upvotes: 1
Views: 3410
Reputation: 15313
If the printer is a network printer (has ethernet port) you may want to try communicating directly with this printer instead of using the printer share (\server\printer). By directly I mean installing it as local tcp/ip printer.
I've always had more reliability when communicating to printers this way rather than using printer shares.
Upvotes: 1
Reputation: 941970
This is a problem that's induced by the printer driver. The call to the native DocumentProperties() API function failed. Unfortunately it doesn't have a good way to indicate exactly what is wrong, an error return doesn't mean anything more than "it didn't work". Beyond the standard 'update the driver' approach, contacting the printer manufacturer for support would be your best bet. They'll want to know exactly what else might be going on with this printer while the call failed. Including the printer state and whether anybody is tinkering with the printer properties.
If this exception repeats well then catching the exception is a possible hack. It happens very early, before anything is done with the printer. Sleep for a couple of seconds and try again. Don't retry forever.
Upvotes: 4