Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 702
  • Last Modified:

Win32_PrintJob not pausing prints in time

I am current creating a small print charger for use at my workplace but I have hit a snag, I am testing the system on a computer that does not serve the printers and it seems to work fine, except for hp 2420 printers. The way it works, to prevent jobs "slipping through" is it pauses the job at the very begining of the program to then checks the user has enough credit etc. but for some reason with these 2420's they just disappear.. they don't pause or print. Does anyone know how to prevent this/why it is happening?

Its as if it dosn't process quick Enough
            string query = "SELECT * FROM Win32_PrintJob";
            using (ManagementObjectSearcher jobQuery = new ManagementObjectSearcher(query))
                using (ManagementObjectCollection jobs = jobQuery.Get())
                    foreach (ManagementObject job in jobs)
                        job.InvokeMethod("Pause", null);
                        string JobID = job.Properties["JobID"].Value.ToString();
                        string JobSize = job.Properties["Size"].Value.ToString();
                        string JobPages = job.Properties["TotalPages"].Value.ToString();
                        string JobOwner = job.Properties["Owner"].Value.ToString();
                        string JobName = job.Properties["Document"].Value.ToString();
                        string PrinterName = job.Properties["Name"].Value.ToString();

Open in new window

  • 4
1 Solution
GuffieAuthor Commented:
It seems to be the start printing immediately setting, is there a way to catch the print job with this set?
your code snippet is not showing how/when you trigger that code, but I would look into using a System.Management.ManagementEventWatcher  
to subscribe on events (you can do it with really short intervals to fetch a job when its created and then do your stuff on the job.
please take a look at another question where I suggested this, where you have links to the documentation and also a code snippet how to implement it.
I am using this already and havnt missed a printjob even when I subscribe on this remotely to a computer on the other side of the globe.
Good luck!
/ Mikael
GuffieAuthor Commented:
Thanks! I will look into that today!
GuffieAuthor Commented:
By the way, this solution worked.
GuffieAuthor Commented:
That code works great but only if 1 document is printed at a time, I want it so for eg if 10 people print at one time it will catch all 10 documents.. Do you know how I could achieve this?

I have explored threading but all 10 threads get triggered on the event.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now