如何在USB打印机上进行打印时收到通知 [英] How to get notified when printing occurs to USB printer
本文介绍了如何在USB打印机上进行打印时收到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我正在使用下面的代码。但只有当我插入或拔出USB打印机时,此代码才会通知我。但是我需要在USB打印机上进行打印时收到通知。我正在使用c#和.netfx4.5。
请帮助我,任何建议都将受到高度赞赏!
问候,Orgil.D
我尝试过:
Now I'm using code below. But this code notifies me only when I plug in or out USB printer. But I need to get notified when printing occurs on USB printer. I am using c# and .netfx4.5.
Please help me, any suggestion would be highly appreciated!
Regards, Orgil.D
What I have tried:
<pre>using LibUsbDotNet.DeviceNotify;
//...
public static IDeviceNotifier UsbDeviceNotifier = DeviceNotifier.OpenDeviceNotifier();
private static void Main(string[] args)
{
// Hook the device notifier event
UsbDeviceNotifier.OnDeviceNotify += OnDeviceNotifyEvent;
// Exit on and key pressed.
Console.Clear();
Console.WriteLine();
Console.WriteLine("Waiting for system level device events..");
Console.Write("[Press any key to exit]");
while (!Console.KeyAvailable)
Application.DoEvents();
UsbDeviceNotifier.Enabled = false; // Disable the device notifier
// Unhook the device notifier event
UsbDeviceNotifier.OnDeviceNotify -= OnDeviceNotifyEvent;
}
private static void OnDeviceNotifyEvent(object sender, DeviceNotifyEventArgs e)
{
// A Device system-level event has occured
Console.SetCursorPosition(0,Console.CursorTop);
Console.WriteLine(e.ToString()); // Dump the event info to output.
Console.WriteLine();
Console.Write("[Press any key to exit]");
}
推荐答案
您必须监控Windows打印作业并检查您的USB打印机是否为输出设备。 />
一些可能有用的链接:
监视打印机队列(.NET)中的作业 [ ^ ]
一种使用WMI控制打印作业的简单方法 [ ^ ]
You have to monitor the Windows print jobs and check if your USB printer is the output device.
Some links which might be helpful:
Monitor jobs in a printer queue (.NET)[^]
A simple approach for controlling print jobs using WMI[^]
这篇关于如何在USB打印机上进行打印时收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文