简体   繁体   English

如何在完成打印任务时得到通知

[英]How to get informed when a print task is completed

I want to get informed when a print job is completed using C# 我想在使用C#完成打印作业时得到通知

I'm uisng C# Winform.I wonder if there is a way that an event can be raised when a print job is completed in a specified print queue.I have tried the following solutions: 我正在使用C#Winform,我想知道是否有一种方法可以在指定的打印队列中完成打印作业时引发事件。我尝试了以下解决方案:

I'm current polling queries from WMI. 我目前正在从WMI查询查询。 It's unreliable because it depends on the interval of the query. 这是不可靠的,因为它取决于查询的间隔。 Sometimes the system deletes the data entry in WMI database after the print job is completed and with a long query interval I could miss a print job, while with a short interval I could put too much extra load. 有时,系统会在打印作业完成后删除WMI数据库中的数据条目,如果查询间隔较长,我可能会错过打印作业,而间隔很短,则可能会增加过多的负载。

I also used PrintQueue.GetPrintJobInfoCollection() which returns an array of PrintSystemJobInfo that raises no event.I have to query their status periodically and leads to the same problem as I mentioned above. 我还使用了PrintQueue.GetPrintJobInfoCollection()返回一个不引发事件的PrintSystemJobInfo数组。我必须定期查询它们的状态,并导致与上述相同的问题。

Though I don't think my messy code is requeired here but i will paste it anyway. 尽管我认为这里不需要我的凌乱代码,但是无论如何我都会粘贴它。

public static PrintQueue GetPrintQueue(string printerName)
        {
            PrintQueue targetPrintQueue = null;
            using (LocalPrintServer printServer = new LocalPrintServer())
            {
                PrintQueueCollection printQueuesOnLocalServer =
                    printServer.GetPrintQueues(new[] {EnumeratedPrintQueueTypes.Local});
                targetPrintQueue =
                    (from PrintQueue printQueue in printQueuesOnLocalServer
                        where printQueue.Name == printerName
                        select printQueue).FirstOrDefault();
            }

            return targetPrintQueue;
        }

public static List<PrintSystemJobInfo> GetPrintJobs(string printerName)
        {
            PrintQueue targetPrintQueue = GetPrintQueue(printerName);
            if (targetPrintQueue != null)
            {
                targetPrintQueue.Refresh();
                return targetPrintQueue.GetPrintJobInfoCollection().ToList();
            }
            else
            {
                throw new Exception();
            }
        }

MORE INFO 更多信息

I read FindNextPrinterChangeNotification very carefully (at least i think that i'm careful enough) and found no bit indicating a print job is done in pdwChange , if this api do meet the requirement I described above, would someone kindly provide me more detail on the realization or an example or something? 我非常仔细地阅读了FindNextPrinterChangeNotification (至少我认为我已经足够小心了),没有发现任何指示pdwChange已完成打印作业的pdwChange ,如果此api确实满足了我上述的要求,请有人为我提供更多详细信息实现或示例或其他内容?

为了实现打印的事件处理,您应该使用FindFirstPrinterChangeNotification函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM