I have a couple thousand of documents i want to generate. When I run the loop in a simple foreach everything works fine. Now I've tried to increase performance by using a parallel.foreach loop and it works somewhat the same except multiple times faster (as expected) but every now and then (roughly 1 in 10000) Prince won't start up and return the following error instead. How can i assure Program start before my .Convert() call?
System.ApplicationException: Error starting Prince: C:\Program Files (x86)\Prince\engine\bin\prince.exe at Prince.StartPrince(String args) at Prince.Convert1(String args) at Prince.Convert(String xmlPath, String pdfPath)
I'm not sure exactly what is causing this. This is the significant code in the StartPrince() method:
if (!pr.HasExited)
{
return pr;
}
throw new ApplicationException("Error starting Prince: " + mPrincePath);
But why is the process exiting immediately? Perhaps you could try changing the exception to include the pr.ExitCode value and see if that is informative?
with a non-static method, limited to 8 simultaneous threads i don't encounter that error. So there indeed seems to be a bottleneck somewhere.. i'll keep looking
until now i've used the nuget wrapper (v.9.00) - i'll use the source file now and will implement pr.exitcode into the log - i guess https://www.nuget.org/packages/Prince/ isn't your official build - right?
We will need to find if there is another way to launch the Prince process that gives more diagnostics, as I can't tell from this whether the program is even running and why not.
Okay, i think i've figured it out. The creation of pdf files works most of the time, but sometimes prince will return that it couldn't quit (i have the pr.convert() in a try/catch block) => Exit(0) - which should be the default case anyway. Now i've added a check to look if the file i wanted to create was created in the catch-block. If that's the case i'm ignoring the returned exception and just continue - i'll try to test if that fixes the behaviour.