我如何检索列表或作业人数从打印机队列

我如何检索列表或作业人数从打印机队列

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

问题描述

我在寻找一种方式来获得的作业列表或数字从一个特定的打印机。在最好的情况下,我希望有一个工作对象的重新presents一个打印作业,其名称在打印队列中。

这是必需的,因为我需要监视打印机的状态,这样我就可以重新注入新的一批文件打印队列不会溢出打印后台处理程序

在此先感谢!

编辑:增加了code溶液片段

 私人诠释GetNumberOfPrintJobs()
{
    LocalPrintServer服务器=新LocalPrintServer();
    PrintQueueCollection queueCollection = server.GetPrintQueues();
    打印队列打印队列= NULL;

    的foreach(打印队列PQ在queueCollection)
    {
        如果(pq.FullName == PrinterName的)
            打印队列= PQ;
    }

    INT numberOfJobs = 0;
    如果(打印队列!= NULL)
        numberOfJobs = printQueue.NumberOfJobs;

    返回numberOfJobs;
}
 

解决方案

您可以在System.Printing命名空间中使用.NET 3.0打印队列类。其NumberOfJobs属性告诉你有多少作业排队,GetPrintJobInfoCollection()返回的所有作业的详细信息。要注意的是它并没有告诉大家,这项工作的收集改变,你需要查询一个计时器任何事件。一旦一秒钟左右应该可以了。

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;
}
解决方案

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.

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

08-04 02:18