Anyway for the events to throw if ...

May 20, 2012 at 7:13 AM

Hi

Is there anyway this component to throw an event for example I am printing 5 copies of a document then an event in PrinterInformationChanged can throw a status like "Printing", "Printed" 5x sort of thing? 5x because there are 5 pages to print.

Coordinator
May 21, 2012 at 1:16 PM

A print job is a single entity so you will only get a single PrinterInformationChanged but I'd expect at least one JobWritten event for each page as it is printed out...?

May 21, 2012 at 1:53 PM

nope. it does throw any after EACH print..

this is my code

public Form1()
{
	InitializeComponent();

	//pmc.JobAdded += new PrinterMonitorComponent.PrintJobEventHandler(pmc_JobAdded);
	pmc.JobAdded += new PrinterQueueWatch.PrinterMonitorComponent.PrintJobEventHandler(pmc_JobAdded);
	pmc.JobWritten += new PrinterMonitorComponent.PrintJobEventHandler(pmc_JobWritten);
	pmc.PrinterInformationChanged += new PrinterMonitorComponent.PrinterEventHandler(pmc_PrinterInformationChanged);
	//pmc.JobSet += new PrinterMonitorComponent.PrintJobEventHandler(pmc_JobSet);

	PrinterInformationCollection pic = new PrinterInformationCollection();
	
	foreach (PrinterInformation pInfo in pic)
	{
		if (pInfo.PrinterName.Contains("Canon"))
		{
			System.Diagnostics.Debug.WriteLine(pInfo.PrinterName);
			pmc.AddPrinter(pInfo.PrinterName);
		}
	}
}

void pmc_JobSet(object sender, PrintJobEventArgs args)
{
	System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString() + " > jobset: " + args.PrintJob.PagesPrinted.ToString());
}

private void Form1_Load(object sender, EventArgs e)
{

}

void pmc_JobAdded(object sender, PrintJobEventArgs e)
{
	System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString() + " > jobadded: " + e.PrintJob.PagesPrinted.ToString());
}

void pmc_JobWritten(object sender, PrintJobEventArgs e)
{
	System.Diagnostics.Debug.WriteLine(DateTime.Now.ToString() + " > jobwritten: " + e.PrintJob.PagesPrinted.ToString());
}

void pmc_PrinterInformationChanged(object sender, PrinterEventArgs e)
{
	System.Diagnostics.Debug.WriteLine(e.PrinterInformation.Copies.ToString());
}

May 21, 2012 at 1:55 PM
Edited May 21, 2012 at 2:02 PM

and this is the output

Canon PIXMA iP1000
1
1
1
5/21/2012 9:46:58 PM > jobadded: 0
5/21/2012 9:46:59 PM > jobwritten: 0
5/21/2012 9:46:59 PM > jobwritten: 0
5/21/2012 9:46:59 PM > jobwritten: 0
5/21/2012 9:46:59 PM > jobwritten: 0
1

well to explain the detail of the output. after running, 

it shows that Canon PIXMA iP1000 then it shows those 3 "1"'s then after clicking the Print button on Print dialog box, it started to show that "jobadded" and just a few, it shows those 4 "jobwritten" messages at once

Coordinator
May 22, 2012 at 4:08 PM

e.PrinterInformation.Copies is only the default number of copies for this printer - not the current number of copies for the current print job.  For that you need args.PrintJob.Copies

I suspect if you have a print spooler then the job written event occurs as data is written to the spool file - not to the actual printer.