本文介绍了WebClient下载崩溃问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好, i做了一个小的异步文件下载器。 这是代码
Hello, i did a small async file downloader. Here's the code
private void button5_Click(object sender, EventArgs e) { downloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(downloader_DownloadFileCompleted); downloader.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(downloader_DownloadProgressChanged); try { label14.ResetText(); label13.ResetText(); progressBar1.Value = progressBar1.Minimum; milestones = new List<Milestone>(new[] { new Milestone { DataSize = 0, Time = DateTime.Now } }); downloader.DownloadFileAsync(new Uri(modlink), textBox1.Text + "/download.zip"); label17.ForeColor = Color.Red; label17.Text = "Status: Downloading..."; downloading = true; button5.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void downloader_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { milestones.Add(new Milestone { DataSize = e.BytesReceived, Time = DateTime.Now }); //Use the last 5 intervals to calculate the download speed. milestones = milestones.Skip(Math.Min(0, milestones.Count - 6)).ToList(); var firstMilestone = milestones.First(); var lastMilestone = milestones.Last(); var speed = (lastMilestone.DataSize - firstMilestone.DataSize) / (lastMilestone.Time - firstMilestone.Time).TotalSeconds; var timeRemaining = TimeSpan.FromSeconds((e.TotalBytesToReceive - e.BytesReceived) / speed); label14.Text = "Percentage: " + string.Format("{0}% ({1})", e.ProgressPercentage, FormatDataSpeed(speed)); label13.Text = "Download Speed: " + string.Format("{0} of {1} ({2})", FormatDataSize(e.TotalBytesToReceive - e.BytesReceived), FormatDataSize(e.TotalBytesToReceive), FormatTime(timeRemaining)); progressBar1.Value = e.ProgressPercentage; } private void downloader_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) { button5.Enabled = true; downloading = false; if (e.Cancelled) { label14.ResetText(); label13.Text = "Download cancelled"; MessageBox.Show("The download was cancelled before completion.", "Download Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (e.Error != null) { MessageBox.Show(e.Error.ToString(), "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { label14.Text = "100%"; label13.Text = "Download complete"; unzip(); //MessageBox.Show("The download completed successfully.", "Download Complete", MessageBoxButtons.OK, MessageBoxIcon.Information); } }</pre>问题是我要以超过2mb / s的速度下载。应用程序崩溃。
The problem is when im going to download with a speed more than 2mb/s. The app crash.
Description: A problem caused this program to stop interacting with Windows. Problem signature: Problem Event Name: AppHangB1 Application Name: 9thapp.exe Application Version: 1.0.0.0 Application Timestamp: 537a174b Hang Signature: 7a8c Hang Type: 0 OS Version: 6.1.7601.2.1.0.400.8 Locale ID: 1033 Additional Hang Signature 1: 7a8c9079a614de92decd9bf2aaae0f5f Additional Hang Signature 2: b046 Additional Hang Signature 3: b0469793c99a5b2e42c175e4de5808c9 Additional Hang Signature 4: 7a8c Additional Hang Signature 5: 7a8c9079a614de92decd9bf2aaae0f5f Additional Hang Signature 6: b046 Additional Hang Signature 7: b0469793c99a5b2e42c175e4de5808c9 Read our privacy statement online: go.microsoft/fwlink/?linkid=104288&clcid=0x0409 If the online privacy statement is not available, please read our privacy statement offline: C:\Windows\system32\en-US\erofflps.txt谢谢 亲切 Gianmarco V.
Thanks Cordially Gianmarco V.
推荐答案
更多推荐
WebClient下载崩溃问题
发布评论