PrintJob的实际总页数(Win32_PrintJob)
我每次使用ManagementEventWatcher进行更改时都会查询Win32_PrintJob WMI类,我获取了有关它的数据,例如:Document,HostPrintQueue,JobId,JobStatus,TotalPages等。 但TotalPages并不代表要打印的实际页数 ,目前看来获取这些数据仍然是printjob还没有完成处理并在那个时刻打开多个页面进行打印但实际总数是其他数字,如何在完成后获取打印作业的实际数量处理? 这是我的代码:
ManagementEventWatcher createPrintJobWatcher; String strComputerName = "."; // Create event query to be notified within 1 milli second of a change in a service WqlEventQuery createPrintJobQuery = new WqlEventQuery("SELECT * FROM __InstanceCreationEvent WITHIN 0.001 WHERE TargetInstance ISA "Win32_PrintJob""); createPrintJobWatcher = new ManagementEventWatcher(); createPrintJobWatcher.Scope = new ManagementScope("\\" + strComputerName + "\root\CIMV2"); createPrintJobWatcher.Query = createPrintJobQuery; // times out watcher.WaitForNextEvent in 1 seconds createPrintJobWatcher.Options.Timeout = new TimeSpan(0, 0, 1); //set the print event handler createPrintJobWatcher.EventArrived += new EventArrivedEventHandler(createPrintJobListener); createPrintJobWatcher.Start(); Console.WriteLine("Listening..."); Console.ReadLine();
createPrintJobListener方法:
static void createPrintJobListener(object sender, EventArrivedEventArgs e) { SelectQuery query = new SelectQuery("Win32_PrintJob"); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query)) using (ManagementObjectCollection printJobs = searcher.Get()) foreach (ManagementObject printJob in printJobs) { Console.WriteLine("c1:", printJob); Console.WriteLine("ID: {0}", printJob.GetPropertyValue("JobId").ToString()); Console.WriteLine("name: {0}", printJob.GetPropertyValue("name").ToString()); Console.WriteLine("status: {0}", printJob.GetPropertyValue("status").ToString()); if (printJob.GetPropertyValue("JobStatus") != null) { Console.WriteLine("JobStatus: {0}", printJob.GetPropertyValue("JobStatus").ToString()); } else { Console.WriteLine("JobStatus: NULLLLLL"); } Console.WriteLine("PC: {0}", printJob.GetPropertyValue("HostPrintQueue").ToString()); Console.WriteLine("TOTOAL PAGES: {0}", printJob.GetPropertyValue("TotalPages").ToString()); } }
WMI可能不足以做到这一点 。
Windows无法可靠地提供页数(或副本等),因此获取准确信息的唯一方法是暂停作业并解析它。 这是一项非常重要的任务,但这里有更多信息 。
上述就是C#学习教程:PrintJob的实际总页数(Win32_PrintJob)分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/936527.html