我正在向打印机发送打印作业,并尝试跟踪它们的状态,以便将其反映在我自己的队列中。
似乎打印作业从未经历过“已打印”、“已完成”状态。
我做了一个小测试程序,看看我是否以错误的方式使用了 .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.
我如何知道文档何时处于“已完成”状态?