Win32_PrintJob not pausing prints in time

Posted on 2009-02-19
Last Modified: 2012-08-14
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

Question by:Guffie
    LVL 1

    Author Comment

    It seems to be the start printing immediately setting, is there a way to catch the print job with this set?
    LVL 6

    Accepted Solution

    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
    LVL 1

    Author Comment

    Thanks! I will look into that today!
    LVL 1

    Author Comment

    By the way, this solution worked.
    LVL 1

    Author Comment

    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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now