私はVisual C# application
を作成していますが、その機能の一部は、ディレクトリに表示された.gz
ファイルを抽出することです。 .gz
ファイルは、コマンドライン引数が実行されると、指定されたディレクトリに表示されます。ファイルがディレクトリに存在するのを待っていますC#
残念ながら、「このファイルが見つかりません」という行に沿って何かが表示されるというエラーが表示されます。これは、.gz
ファイルをあまりにも速く抽出する行を読み取る理由によるものです。
つまり、コマンドライン引数が実行される前に.gz
ファイルを実行しようとしていて、実際にファイルをディレクトリに配置しています。
私のプログラムが次の行を読み続ける前に、ファイルがディレクトリに現れるのを待つ方法を見つけたいと思います。
以下は私のコードですが、何か助けていただければ幸いです!ありがとう!
else if (ddlDateType.Text == "Monthly" || ddlDateType.Text == "")
{
//Check if Monthly date entered is valid
if (DateTime.TryParseExact(txtDate.Text, MonthlyFormat, null,
System.Globalization.DateTimeStyles.None, out Test) != true)
{
MessageBox.Show("Enter a valid date.\nFormat: yyyyMM");
}
else
{
//Method that executes an arugment into the command prompt
ExecuteCommand();
//Method that extracts the file after it has already appeared in the directory
ExtractFile();
/*
Goal is to wait for the file to appear in the directory before it executes
the ExtractFile() method.
*/
}
}
私の最初の考えは、while(!File.Exists(theFile)){System.Threading.Thread.Sleep(1000);を実行することです。 } ' – Quantic