Question

I am designing an app which needs to identify if printer is connected or not. I know the methods by WMI to enumerate connected printers. But what is to be done if printer connected after application start up? Do we got any events or APIs for that? Or I have to check frequently using WMI code?

for simplicity I tried LocalPrintServer class like this :

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;


                }

You knows it will show the installed printers it runs on application startup. The problem is it cant identify if a printer connected after application start up.If we have any events for that,I could call this method to re-enumerate printer unless am I supposed for a thread or while loop ??

Thanks

Was it helpful?

Solution

Resolved the issue by setting a timer to pull details .

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top