サーバー上の Uri パスから zip ファイルを収集する Windows サービスを作成しています。私が直面している問題は、サービスがそれを収集しようとしたときに、zip ファイルがまだサーバーに書き込まれていることです。Thread.Sleep(15000)
ファイルをダウンロードするための呼び出しを行う前にa を配置すると、正常に動作します。ビデオ アラームを処理する場合、その遅延は許容できません。可能であれば、while ループにチェックを追加して、ダウンロード関数を呼び出す前にサーバー URI からファイルをダウンロードする準備ができているかどうかを確認したいと思います。これは可能ですか?
非同期 WebClient を使用して zip ファイルをダウンロードしています。
internal void DownloadZippedFile(string eventId)
{
try
{
Logger.LogInformation("Extracing Video for event: " + eventId);
using (WebClient webClient = new WebClient())
{
string urlPath = sureViewZipHost + "/archiveevent?user=" + sureViewUserId + "&password=" + sureViewPassword + "&event=" + eventId;
string tempPath = Path.GetTempPath();
long lReceived = 0;
long lTotal = 0;
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadCompleted);
webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e)
{
Logger.LogInformation("downloaded {0} of {1} bytes. {2}% complete", e.BytesReceived, e.TotalBytesToReceive, e.ProgressPercentage);
// Assign to outer variables to allow busy-wait to check.
lReceived = e.BytesReceived;
lTotal = e.TotalBytesToReceive;
};
webClient.DownloadFileAsync(new Uri(urlPath), tempPath + "//" + eventId + ".zip",eventId);
}
}
catch (Exception ex)
{
Logger.LogError("Error extracting Video " + ex.Message);
}
}
上記のコードを使用して例外がスローされることはありません。部分的にダウンロードした zip を開くと、問題が見つかりました。含まれているものは次のとおりです。
400不正な要求
System.IO.IOException: 別のプロセスで使用されているため、プロセスはファイル 'C:\FileStore\G98\E16884\R6507679\JpegBackup022620132102384484.zip' にアクセスできません。