Once you've started the process with Process.Start
you need to wait for the program to exit like this:
newProcess.WaitForExit();
You shouldn't need to manually .Kill()
the process unless it needs to be interrupted.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I have bund of pdf files in a folder. They have naming convention. I need to use system.diagnostics.process to use third party vendor exe to create combined pdf out of those files. I have criteria to loop through.
Here is my code:
foreach (string st in stringlist)
{
string arguments = @"C:\Files\ + CompanyName + "_" + BranchName + "_*.pdf cat output " + @"C:\\Files\+ CompanyName + "_" + BranchName + "_Combined-" + pYear + ".pdf";
ProcessStartInfo info = new ProcessStartInfo(pPdfUtility);
info.Arguments = arguments;
info.RedirectStandardError = true;
info.RedirectStandardOutput = true;
info.CreateNoWindow = true;
info.UseShellExecute = false;
Process newProcess = Process.Start(info);
if (newProcess != null && !newProcess.HasExited)
newProcess.Kill();
}
When I run in debug step into, if I give gap, then working. Otherwise nothing happening. Do I need to give process to finish 30 seconds or something before it goes into the loop. It's never going into kill line.
Please let me know how to do it
I am not doing async, await etc. This is old application. If I need to use async and await, need to modify method signature which gets called and entire chain has to be converted to async.
Thanks,
Once you've started the process with Process.Start
you need to wait for the program to exit like this:
newProcess.WaitForExit();
You shouldn't need to manually .Kill()
the process unless it needs to be interrupted.