进程WaitForExit不等待

编程入门 行业动态 更新时间:2024-10-27 02:24:08
本文介绍了进程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不等待

本文发布于:2023-11-06 10:02:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   WaitForExit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!