简体   繁体   English

如何检查进程在 WCF c# 中终止

[英]How to check that process is terminated in WCF c#

I have a WCF rest service, and inside it I hava a execution of a Process:我有一个 WCF 休息服务,在它里面我有一个进程的执行:

        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "cmd.exe";
        startInfo.Arguments = "/C " + Properties.Resources.NAME_APP_IAL + " " + ...);
        startInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(@"" + ...);
        startInfo.CreateNoWindow = false;
        startInfo.UseShellExecute = false;
        Process oProcess = null;
        try
        {
            oProcess = Process.Start(startInfo);
            bool bStep = true;
            while (bStep)
            {
                Process[] oPro = Process.GetProcessesByName(Properties.Resources.NAME_APP_IAL);
                if (oPro == null || oPro.Count() == 0 ) bStep = false;
            }
        }

        catch (Win32Exception ex)
        {
            throw ..
        }

The process works well,这个过程运作良好,

but after it finished I get a file as result,但完成后我得到了一个文件,

my problem that the process is terminated quickly so that I get empty file: So how can I fix it?我的问题是进程很快终止,所以我得到空文件:那么我该如何解决呢? to be sure that the processus is finished or terminated at first, Also with this verify if I have a exception or the process is blocked or anything else?确保流程首先完成或终止,还要通过此验证我是否有异常或流程被阻止或其他任何事情? how can I recognize it ?我怎样才能认出它?

Thanks for your help and for your suggestion and advice,感谢您的帮助以及您的建议和建议,

You need to use WaitForExit.您需要使用 WaitForExit。 See dotnetperls .参见 dotnetperls

   using (Process exeProcess = Process.Start(startInfo))
   {
       exeProcess.WaitForExit();
   }

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

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