如何从打印机队列中检索作业列表或数量?

How do I retrieve a list or number of jobs from a printer queue?(如何从打印机队列中检索作业列表或数量?)

本文介绍了如何从打印机队列中检索作业列表或数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种从特定打印机获取作业列表或数量的方法.在最好的情况下,我希望有一个作业对象",它代表一个打印作业及其在打印队列中的名称.

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

提前致谢!

添加解决方案的代码片段

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;
}

推荐答案

您可以在 System.Printing 命名空间中使用 .NET 3.0 PrintQueue 类.它的 NumberOfJobs 属性告诉您有多少作业排队,GetPrintJobInfoCollection() 返回所有作业的详细信息.请注意,它没有任何事件告诉您作业集合已更改,您需要使用计时器进行轮询.一秒钟左右应该没问题.

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.

这篇关于如何从打印机队列中检索作业列表或数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何从打印机队列中检索作业列表或数量?