System.Printing跳过一些工作状态状态?

时间:2013-05-12 16:31:21

标签: .net system.printing print-spooler-api

我正在向打印机发送打印作业,并尝试跟踪其状态,以便将其反映在我自己的队列中。

似乎打印作业从未经历过“已打印”,“已完成”状态。

我制作了一个小型测试程序,看看我是否使用了.net对象,但这种情况仍然存在。我运行我的测试程序来查询新的打印作业,一旦有一个我严重查询它并每次刷新以查看其状态并确保我不会遗漏任何内容。

PrintServer ps = new PrintServer(@"\\printServer");
PrintQueue pq = new PrintQueue(ps, "PDF Writer - bioPDF");
PrintSystemJobInfo jobInfo = null;

while (jobInfo == null)
{
    pq.Refresh();
    var printJobs = pq.GetPrintJobInfoCollection(); 

    foreach (var printJob in printJobs)
    {
        printJob.Refresh();

        jobInfo = printJob;
        break;
    }

    Thread.Sleep(100);
}

PrintJobStatus jobStatus = PrintJobStatus.None;
PrintJobStatus prevJobStatus = PrintJobStatus.None;
while (true)
{
    try
    {
        jobInfo.Refresh();
    } catch { }

    prevJobStatus = jobStatus;
    jobStatus = jobInfo.JobStatus;

    if (jobStatus != prevJobStatus)
    {
        Console.WriteLine("**UPDATE**");
        SpotTroubleUsingProperties(jobInfo); // Microsoft example method that prints a description of each possible job status
    }

    Thread.Sleep(20);
}

即使打印文档,我得到的结果是:

**UPDATE**
The job is spooling now.
**UPDATE**
The job is printing now.
**UPDATE**
The user or someone with administration rights to the queue has deleted the job. It must be resubmitted.

如何知道文档何时处于“已完成”状态?

2 个答案:

答案 0 :(得分:2)

除非您为打印机启用“保留打印文档”选项,否则您永远不会看到Completed状态,因为打印作业会在完成后立即删除。转换为Printing-->Deleting,而非Printing-->Completed-->Deleting

因此,您有两个可能的信号表明作业已完成:1)当它进入Deleting状态时2)当它从队列中消失时。据我所知,没有办法区分被删除的打印作业,因为它已完成,也因为某人或其他程序将其删除。

答案 1 :(得分:1)

我只是在测试类似的情况并且跟踪记录输出,没有“保留打印文档”标志集:

list2.filter(item -> element.getKey().equals(item.getKeyNextYear())).forEach(...)

似乎可能与打印机/驱动程序有关。

用于获取此输出的代码:

Info: 11/24/2017 12:08:18 PM - JobStatus for document testA4.pdf is Printing, Retained.
Info: 11/24/2017 12:08:22 PM - JobStatus for document testA4.pdf changed from Printing, Retained to Retained.
Info: 11/24/2017 12:08:22 PM - JobStatus for document testA4.pdf changed from Retained to Completed, Retained.
Info: 11/24/2017 12:08:22 PM - Document testA4.pdf marked as Completed by printer.
Info: 11/24/2017 12:08:33 PM - JobStatus for document testA4.pdf changed from Completed, Retained to Deleted.