我试图获取最近使用c#推送到打印机队列的打印作业状态。我可以看到PrintJobInfoCollection
类检查Printer spool文件夹中存在的所有打印作业的状态。
例如,在上午10点有一个工作标识符“ 17”,在上午10.15有一个另一个工作标识符“ 18”。我希望有一个代码可以单独检查标识符18的工作状态。
我现在正在使用下面的代码检查打印作业的状态。
private void GetJobStatus()
{
string jobStatus = string.Empty;
try
{
PrintQueue PDFprinterQueue = printServerJob.GetPrintQueue(_selectedPrinter);
PrintJobInfoCollection pjc = PDFprinterQueue.GetPrintJobInfoCollection();
foreach (var job in pjc)
{
switch (job.JobStatus)
{
case PrintJobStatus.Paused:
jobStatus = "JOB_STATUS_PAUSED";
break;
case PrintJobStatus.Error:
jobStatus = "JOB_STATUS_ERROR";
break;
case PrintJobStatus.Deleting:
jobStatus = "JOB_STATUS_DELETING";
break;
case PrintJobStatus.Spooling:
jobStatus = "JOB_STATUS_SPOOLING";
break;
case PrintJobStatus.Printing:
jobStatus = "JOB_STATUS_PRINTING";
break;
case PrintJobStatus.Offline:
jobStatus = "JOB_STATUS_OFFLINE";
break;
case PrintJobStatus.PaperOut:
jobStatus = "JOB_STATUS_PAPEROUT";
break;
case PrintJobStatus.Printed:
jobStatus = "JOB_STATUS_PRINTED";
break;
case PrintJobStatus.Deleted:
jobStatus = "JOB_STATUS_DELETED";
break;
case PrintJobStatus.Blocked:
jobStatus = "JOB_STATUS_BLOCKED";
break;
case PrintJobStatus.UserIntervention:
jobStatus = "JOB_STATUS_USERINTERVENTION";
break;
case PrintJobStatus.Restarted:
jobStatus = "JOB_STATUS_RESTARTED";
break;
case PrintJobStatus.Completed:
jobStatus = "JOB_STATUS_COMPLETED";
break;
case PrintJobStatus.Retained:
jobStatus = "JOB_STATUS_RETAINED";
break;
}
if (string.IsNullOrEmpty(jobStatus))
{
// Assuming everything is good:-)
jobStatus = "GOOD";
}
}
}
catch (InvalidPrinterException invptrexp)
{
jobStatus = "JOB_STATUS_ERROR";
}
finally
{
if (printServer != null) printServer.Dispose();
}
}
任何建议都会很有帮助。 预先感谢。