【问题标题】:printer connected event打印机连接事件
【发布时间】:2013-05-10 13:49:06
【问题描述】:

我正在设计一个需要识别打印机是否连接的应用程序。我知道 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 循环??

谢谢

【问题讨论】:

  • 您尝试过任何方法吗?展示你的作品..
  • 我无法直接帮助您,只能尝试使用 Google 搜索 Duncan Edwards Jones 的任何博客条目/代码。他似乎是合适的 .net 打印大师。
  • 我会从一个会不断轮询信息的 BackgroundWorker 开始

标签: c# printers


【解决方案1】:

通过设置计时器来提取详细信息解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    • 2016-12-01
    • 1970-01-01
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多