Monitoring program print
Good afternoon. I have a source program that monitors the status of the printer (start printing, stop, etc.). Here is the code that displays information about the print:
MethodInvoker invoker = () =>
{
lbSpoolChanges.Items.Add(e.JobID + " - " + e.JobName + " - " + e.JobStatus);
};
if (lbSpoolChanges.InvokeRequired)
{
Invoke(invoker);
}
else
{
invoker();
}`
You can also call the property e.JobInfo.NumberOfPagesPrinted and line will be a
lbSpoolChanges.Items.Add(e.JobID + " - " + e.JobName + " - " + e.JobStatus + " - " + e.JobInfo.NumberOfPagesPrinted);
but in debug error pops up "The calling thread can not get access to this object as the owner of this object is another thread.开发者_Python百科." Tell me where you want to call this property. Source included. And can somebody tell how to do so automatically control all the printers (eg 4), and not set in the program. Thanks in advance.
Does it work if you write the invoker as an Action like this, and pass the delegate parameters using BeginInvoke?
Action<string> invoker = (x) =>
{
lbSpoolChanges.Items.Add(x);
};
if (this.InvokeRequired)
{
this.BeginInvoke(invoker, e.JobID + " - " + e.JobName + " - " + e.JobStatus);
}
else
{
invoker(e.JobID + " - " + e.JobName + " - " + e.JobStatus);
}
精彩评论