我想赶上我们的本地网络提交到打印机的每个打印作业。我想要显示像作业名作业的一些特性,提交时间等。
I am trying to catch every print jobs submitted to printer in our local network. I want to display some properties of the job like job name, submit time and so on.
我尝试了,而循环,但它没有赶上我的打印作业,也许怎么一回事,因为它同时线程睡眠发生。有没有办法,我可以注册和处理事件?我不想把所有的CPU资源完成这个任务infinetly循环。
I tried a while loop but it didn't catch my print job, maybe beacuse it happened while the thread was sleeping. Is there an event that I can register and handle? I don't want to spend all of the CPU resource for this task infinetly looping.
我尝试这样做:
public static void WritePrinterJobs()
{
while (true)
{
foreach (var job in LocalPrintServer.GetDefaultPrintQueue().GetPrintJobInfoCollection())
{
Console.WriteLine(job.Submitter + " " + job.TimeJobSubmitted.ToShortDateString());
}
Thread.Sleep(100);
}
}
编辑: 在code其实上面的工作,你不需要去低级别的,如果它不为你工作,我的错误是没有正确配置默认打印机。
The code above actually works, you don't need to go lower level if it does work for you, my mistake was not configuring default printer correctly.
我找到了解决办法。对于那些正在寻找一种方法来处理打印作业的事件来看一看:
I found the solution. For those are searching for a way to handle print job events take a look:
FindFirstPrinterChangeNotification
和也工作code可以发现的监控打印作业
and also a working code can be found Monitoring print jobs