进程WaitForExit不等待 [英] Process WaitForExit not waiting

查看:62
本文介绍了进程WaitForExit不等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了Print spooler应用程序以异步打印pdf.

I have created Print spooler application to print pdf asynchronously.

(应用程序使用veryPDF命令从网络打印机进行打印)

(Application uses veryPDF command to print from network printer)

这里是代码

   var procStartInfo = new System.Diagnostics.ProcessStartInfo("cmd", " /c" + "E:\pdfprint_cmd\pdfprint.exe -$ 388444444448350FA394 E:\PrintSpoolerApplication\PrintSpoolerApplication\bin\Debug\45940.pdf");
   procStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
   procStartInfo.Verb = "runas";
   procStartInfo.UseShellExecute = false;
   procStartInfo.CreateNoWindow = true;
   var proc = new System.Diagnostics.Process();
   proc.StartInfo = procStartInfo;
   proc.Start();
   proc.WaitForExit();

// Some stuff

但是它没有等待WaitForExit代码.即使我的文档在打印机队列中,它也确实执行了(这里//有些东西).

But It did not Wait on WaitForExit code. It did executing (here //Some stuff) even if my document is in printer queue.

还有其他方法可以在完成打印时发出通知吗?

Is there any other way that notify when printing is done?

推荐答案

您的代码等待 cmd.exe 完成,(可能)在启动 pdfprint.exe后立即终止作为子进程.我建议你

Your code waits for cmd.exe to finish, which (probably) terminates immediately after it has started pdfprint.exe as a child process. I suggest you

  • 要么直接启动 pdfprint.exe (为什么仍然需要Windows命令行?)
  • 或找到子进程的Process对象-例如通过WMI,按此处所述进行操作-等待那个进程退出.
  • either start pdfprint.exe directly (why do you need the Windows command line here anyway?)
  • or find the Process object of the child process -- e.g. through WMI, as described here -- and wait for that process to exit instead.

但是,这两种方法仅在 pdfprint.exe 实际上等待计划的打印作业完成时才起作用.我不知道该工具,所以我不知道它的行为是否如此.如果没有,则必须访问打印队列,不建议使用(如汉斯在其评论中指出的那样).

However, both approaches only work if pdfprint.exe actually waits for the scheduled print job to be completed. I don't know the tool, so I have no idea if it behaves that way. If it doesn't, you would have to access the print queue, which (as pointed out by Hans in his comment) is not recommended.

这篇关于进程WaitForExit不等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆