我正在为我工作的公司编写一个C#程序,该程序将启动一个创建PDF文件并打开PDF文件的PHP脚本。目前,我的代码如下:
// 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);
现在,我不喜欢整个 "Sleep()
指定时间,希望文件存在时再执行" 的做法。所以我的问题是,是否可行/更好的方法是使用 do
循环并说:
do
{
// Do nothing until the file exists
} while (!File.Exists(filePath));