指定されたファイルのリストからダウンロードし、進行中の個々のダウンロードの進行状況バーを表示するwpfでファイルダウンローダーを作成しています....リストは最大1000ファイルです。
私はすべてのコードと詳細を解決しましたが、ファイルをキューに入れる方法が 1 つあります。以下のコードを検討してください。
private bool Download(String url, int i)
{
String FileName = "some location.mp4";
label2.Content = "Downloading : " + ht[current.ToString()].ToString();
progressBar1.Value = 0;
try
{
if (url.Equals(Constants.NotFound))
return false;
if (File.Exists(FileName))
{
current++;
if (current <= total)
Download(ht[current.ToString()].ToString(), current);
else
{
this.WindowState = System.Windows.WindowState.Normal;
MessageBox.Show("Download Finished");
}
return true;
}
wc.DownloadFileAsync(new Uri(url), FileName);
return true;
}
catch
{ return false; }
}
完全なイベントをキャプチャするために、イベント完了ハンドラーを次のように記述しました。
void wc_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
current++;
if (current <= total)
Download(ht[current.ToString()].ToString(), current);
else
{
progressBar1.Value = 100;
label2.Content = "Download Finished.";
label1.Content = "100 %";
this.WindowState = System.Windows.WindowState.Normal;
MessageBox.Show("Download Finished");
}
}
これは、ダウンロードされるファイルがまだ存在しない場合に完全に機能しますが、ファイルが事前に存在する場合、ダウンロード関数は再帰ループになり、後続の関数呼び出しが戻るまで値を返しません。数千のビデオを考慮すると、巨大になる可能性がありますメモリ上でも。
だから、これを回避する方法/それを乗り越える方法、または私が使用している別のアプローチを使用する方法はありますか??
では、よろしくお願いします....:)