I'm looking for a way to get a list or number of jobs from a particular printer. In the best case I would want to have a "Job object" that represents one print job and its name in the print queue.
This is required because I need to monitor the state of a printer so I can refill the print queue with a new batch of documents without overflowing the print spooler
Thanks in advance!
Edit: added code fragment of solution
private int GetNumberOfPrintJobs()
{
LocalPrintServer server = new LocalPrintServer();
PrintQueueCollection queueCollection = server.GetPrintQueues();
PrintQueue printQueue = null;
foreach (PrintQueue pq in queueCollection)
{
if (pq.FullName == PrinterName)
printQueue = pq;
}
int numberOfJobs = 0;
if (printQueue != null)
numberOfJobs = printQueue.NumberOfJobs;
return numberOfJobs;
}
In Windows, a built-in service called Print Spooler temporarily stores all print jobs until they're printed. These print jobs are stored by Windows as files in a folder associated with the Print Spooler service. Luckily, when a print job is stuck in the queue, you can manually remove it from the Print Spooler.
View information about completed print jobs After you print, you can view information about a document you printed, such as the time and date. On your Mac, choose Apple menu > System Preferences, then click Printers & Scanners . Select the printer you used in the list at the left, then click Open Print Queue.
You can use the .NET 3.0 PrintQueue class in the System.Printing namespace. Its NumberOfJobs property tells you how many jobs are queued, GetPrintJobInfoCollection() returns details on all the jobs. Beware that it doesn't have any events that tells you that the job collection changed, you need to poll with a timer. Once a second or so ought to be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With