I'm using Inkscape to convert images from PDF to SVG using the following code:
internal static void ConvertImageWithInkscapeToLocation(string baseImagePath, string newImagePath, bool crop = true)
{
InkscapeAction(string.Format("-f \"{0}\" -l \"{1}\"", baseImagePath, newImagePath));
}
internal static void InkscapeAction(string inkscapeArgs)
{
Process inkscape = null;
try
{
ProcessStartInfo si = new ProcessStartInfo();
inkscape = new Process();
si.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
si.FileName = inkscapePath; // the path to Inkscape.exe, defined elsewhere
si.Arguments = inkscapeArgs;
si.CreateNoWindow = true;
inkscape.StartInfo = si;
inkscape.Start();
}
finally
{
inkscape.WaitForExit();
}
}
It's a fairly straightforward "launch app with arguments, wait for close" set up and it works well; the only problem is that on slower machines, the image conversion process (and presumably the inkscape.WaitForExit()) takes too long and this dialog message is displayed:

Clicking on "Switch to..." pops up the Windows Start Menu (I'm guessing because I'm hiding the process); "Retry" will bring the message back up over and over again until the process finishes. Is it possible to entirely repress the message box, and automatically retry until it goes through? Can I at least extend the timeout before the message is displayed?
There are some ways to do it:
1-A dirty cheap way is to wait with a timeout (WaitForExit(timeout)), do a DoEvents (I assume you are doing it in a winforms app in the main thread), check if process finished and loop until it:
finally
{
while(!inkScape.HasExited)
{
inkscape.WaitForExit(500);
Application.DoEvents();
}
}
2-The right way is to do it in another thread and then signal your main program to continue
ThreadPool.QueueUserWorkItem((state) => { ConvertImageWithInkscapeToLocation... });
If you do it in another thread remember CrossThreadException, don't update the UI from the thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With