こんにちは私は.NET Framework 4.5.2を対象としたWPFプラットフォームで作業しています。私は自分のアプリケーション用のダウンローダを作成しています。ここにコード:ダウンロードの一時停止と再開WPF
private void Download(Dictionary<int, FileAndLinkClass> MyLinks)
{
ApplicationDownloadThread = new Thread(() =>
{
foreach (KeyValuePair<int, FileAndLinkClass> item in MyLinks)
{
fileNo++;
WebClient myWebClient = new WebClient();
myWebClient.DownloadProgressChanged += MyWebClient_DownloadProgressChanged;
myWebClient.DownloadFileCompleted += MyWebClient_DownloadFileCompleted;
// Download the Web resource and save it into the current filesystem folder.
string downloadedFileAdress = System.IO.Path.Combine(fileLocation, $"{item.Value.FileName}");
myWebClient.DownloadFileAsync(new Uri(item.Value.Link), downloadedFileAdress);
while (myWebClient.IsBusy)
{
}
}
});
ApplicationDownloadThread.IsBackground = false;
ApplicationDownloadThread.Start();
//UnZipAndCreateUpdatePackage(MyLinks);
}
私はボタンをクリックしてダウンロードを一時停止する必要があり、別のボタンをクリックしてダウンロードを再開する必要があります。私は.set()
AutoResetイベントのプロパティと同じの.Reset()
プロパティで動作しようとしましたが、動作しませんでした。 私は助けが必要です。マイボタンクリックコードは以下のとおりです。
private AutoResetEvent waitHandle = new AutoResetEvent(true);
private void StartDownloadBtn_Click(object sender, RoutedEventArgs e)
{
waitHandle.Set();
}
private void StopDownloadBtn_Click(object sender, RoutedEventArgs e)
{
waitHandle.Reset();
}
また、私は、このリンクHow to pause/suspend a thread then continue it?を試してみました。何も起こらない
私もAdding pause and continue ability in my downloaderに行ったことがありますが、上記のコードに解決策を組み込むことができませんでした。UIのダウンロードの進行状況も更新しています。
は、あなたがこのようなSTHを試してみました:http://stackoverflow.com/questions/2430930/how-to-pause-suspend-a-thread-then- continue-it – bakala12
@ bakala12はい私は上記を試しました。いいえ結果 –
[私のダウンローダで一時停止と継続能力を追加する]の可能な複製(http://stackoverflow.com/questions/15995705/adding-pause-and-continue-ability-in-my-downloader) – slawekwin