I’m writing a C# program for the company I work for that will launch a PHP script which creates a PDF, and then opens the PDF file. Right now, I have:
// launch the PHP page to generate my pdf report
Process.Start(phpFile);
// wait for the report to exist
Thread.Sleep(waitTime);
// open the report
Process.Start(filePath);
Now, I’m not a fan of the whole “Sleep() for a specified time in hopes of the file existing when it’s done”. So my question is, is it feasible/better to use a do loop and say:
do
{
// Do nothing until the file exists
} while (!File.Exists(filePath));
Why not use a FileSystemWatcher ?
Set the Path and Filter property and subscribe to the Created event.