简体   繁体   English

监控程序打印

[英]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 您也可以调用属性e.JobInfo.NumberOfPagesPrinted,并且line将是

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. 有人可以告诉您如何做到这一点吗?它会自动控制所有打印机(例如4台),而不是在程序中进行设置。 Thanks in advance. 提前致谢。

Does it work if you write the invoker as an Action like this, and pass the delegate parameters using BeginInvoke? 如果您像这样将调用程序编写为Action并使用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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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