JobSize is always 0

May 6, 2014 at 7:14 PM
I'm simply doing this:
        pmon.JobDeleted += pmon_JobDeleted_see_size;
        pmon.JobAdded += pmon_JobAdded_see_size;
[...]
    private static void pmon_JobAdded_see_size(object sender, PrintJobEventArgs e)
    {
        Console.WriteLine("job added: size " + e.PrintJob.JobSize);
    }

    private static void pmon_JobDeleted_see_size(object sender, PrintJobEventArgs e)
    {
        Console.WriteLine("job deleted: size " + e.PrintJob.JobSize);
    }
In order to get the job size, but the console always write "size 0".

With this horrible code, I can view the size (most of times).
    private static void pmon_JobAdded(object sender, PrintJobEventArgs e)
    {
        while (e.PrintJob.JobSize == 0)
        {
            e.PrintJob.Paused = true;
        }
        e.PrintJob.Paused = false;
    }
What I'm doing wrong? Is this a good approaching (using while (job == 0) )? I don't think so...
Coordinator
May 7, 2014 at 7:43 AM
Hi

The events occur as follows:-
1) Job added (1) - a new spool file has been created and has been given a name, but nothing is in the file
2) Job Written (1 or more) - a bunch of data have been written to that file or to the printer
3) Job Set (0 or more) - The user controllable properties of the job (paused, priority etc) have changed
4) Job Deleted (1) - The print is complete and the spool file has been deleted

The JobSize comes from the number of bytes in this spool file - therefore it is only valid after the job is added and before the job is deleted...you should use the JobWritten event and when .Spooled == true; then you have the correct job size.

If you want it to spool before printing you can set that as a property of the printer in Control Panel, or use the component .PauseAllPrintJobs property and only unpause the job in the .JobWritten event if the .Spooled == true;