简体   繁体   中英

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.." 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM