2
我正在設計一個應用程序,它需要識別打印機是否連接。我知道WMI列舉連接的打印機的方法。但是,如果打印機在應用程序啓動後連接,該怎麼辦?我們是否有任何事件或API?或者我必須經常使用WMI代碼進行檢查?打印機連接事件
爲簡單起見,我試過LocalPrintServer
類是這樣的:
PrintQueue printQueue = null;
LocalPrintServer localPrintServer = new LocalPrintServer();
// Retrieving collection of local printer on user machine
PrintQueueCollection localPrinterCollection =
localPrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
System.Collections.IEnumerator localPrinterEnumerator =
localPrinterCollection.GetEnumerator();
while(localPrinterEnumerator.MoveNext())
{
// Get PrintQueue from first available printer
printQueue = (PrintQueue)localPrinterEnumerator.Current;
if (!printQueue.IsOffline)
{
string s = "Printer found " + printQueue.FullName.ToString();
listBox1.Items.Add(s);
bDeviceFound = true;
button1.Enabled = bDeviceFound;
}
你知道它會顯示在其上運行的應用程序啓動時安裝的打印機。問題是無法確定應用程序啓動後是否連接了打印機。如果我們有任何事件發生,我可以調用這個方法來重新枚舉打印機,除非我是爲了線程或while循環?
謝謝
你有沒有試過_anything_?顯示你的工作.. – 2013-04-10 06:43:50
請看我的工作 – Zigma 2013-04-10 06:50:47
我不能直接幫助你,但嘗試谷歌的任何博客條目/代碼鄧肯愛德華瓊斯。他似乎是適當的.net打印大師。 – svenv 2013-04-10 07:30:45