Monitor all print queues computer

Apr 14, 2013 at 3:29 AM
Edited Apr 14, 2013 at 5:27 AM
I am developing an application to monitor print queues computer.
I wrote a code to call the method several times StartWatching, using threads, but is repetindos several times in execution.
            Printer p = new Printer();
            Filas f = new Filas();

            //f.CadastroFilas();

            List<string> filas = f.recuperaFilas();

            Thread[] exec = new Thread[filas.Count];

            for (int i = 0; i < filas.Count; i++)
            {
                ParameterizedThreadStart start = new ParameterizedThreadStart(p.StartWatching);
                exec[i] = new Thread(start);
                exec[i].Start(filas[i]);
            }

class Printer
    {
        private PrinterMonitorComponent mPr;

        public void StartWatching(object PrinterDeviceName)
        {

            mPr = new PrinterMonitorComponent();

            mPr.MonitorPrinterChangeEvent = false;

            mPr.JobAdded += PegaSpool;

            try
            {
                mPr.DeviceName = PrinterDeviceName.ToString();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n==================" + e.StackTrace);
            }
        }
Is there any other method in printerqueuewatch to perform this operation without using threads?

I tried using the métdo AddPrinter (deviceName) in a list with the names of queues,
but do not quite understand the operation, the system always considers that the last printer added is to be monitored.
class Printer
    {
        private PrinterMonitorComponent mPr;

        public void StartWatching(List<string> PrinterDeviceName)
        {

            mPr = new PrinterMonitorComponent();

            mPr.MonitorPrinterChangeEvent = false;


            mPr.JobAdded += PegaSpool;
            

            try
            {
                //mPr.DeviceName = Convert.ToString(PrinterDeviceName);
                for (int i = 0; i < PrinterDeviceName.Count; i++)
                {
                    mPr.AddPrinter(PrinterDeviceName[i].ToString());
                     
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n==================" + e.StackTrace);
            }
           
            
        }
Apr 14, 2013 at 4:23 PM
I solved the problem by using an array of objects of type PrintMonitor.
thank you
p[i] = new Printer();
                p[i].StartWatching(filas[i]);
Aug 17, 2013 at 11:33 AM
Can you please post the code.

I tried this but didn't get the success.
PrintMonitor[] objPrint = new PrintMonitor[2];

It has 

        public string DLLName { get; }
        public string Environment { get; }
        public string Name { get; }
Aug 17, 2013 at 11:35 AM
Vishal230 wrote:
Can you please post the code.

I tried this but didn't get the success.
PrintMonitor[] objPrint = new PrintMonitor[2];

It has 

        public string DLLName { get; }
        public string Environment { get; }
        public string Name { get; }
Coordinator
Aug 19, 2013 at 7:57 PM
For monitoring more than one printer don't set the DeviceName properety - use the Addprinter method.

One component instance can monitor many printers...