Click to See Complete Forum and Search --> : Monitoring print jobs in C#- Large Jobs give wrong number of pages


nkosinathi
February 15th, 2005, 09:02 AM
I can monitor print jobs and get print events properly using the code snippets below


/*Creating a query statement for printer events*/

WqlEventQuery query = new WqlEventQuery();

query.EventClassName = "__InstanceOperationEvent";

query.Condition = @"TargetInstance ISA 'Win32_Printer'";

query.WithinInterval = new TimeSpan(0,0,0,0,1);



/*Setting a watcher for the printer events*/

ManagementEventWatcher watcher = new ManagementEventWatcher(scope, query);


watcher.EventArrived += new EventArrivedEventHandler(Service.onEvent

//And then wait for print events using



watcher.WaitForNextEvent();


/**************
The problem is, for big print jobs such printing big PDF files, the event is thrown before the job has finished spooling. Resulting in a print job object with a smaller number of pages when i retrieve them using
***************/


ManagementClass c = new ManagementClass("Win32_PrintJob");

ManagementObjectCollection moc = c.GetInstances();

/*****
How can i make the program wait for a print job to finish spooling before it throws an event sso i can get the right number of pages ??
****/


Thanx in Advance