WebClient下载崩溃问题

编程入门 行业动态 更新时间:2024-10-25 12:24:45
本文介绍了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&lt;Milestone&gt;(new[] { new Milestone { DataSize = 0, Time = DateTime.Now } }); downloader.DownloadFileAsync(new Uri(modlink), textBox1.Text + &quot;/download.zip&quot;); label17.ForeColor = Color.Red; label17.Text = &quot;Status: Downloading...&quot;; downloading = true; button5.Enabled = false; } catch (Exception ex) { MessageBox.Show(ex.ToString(), &quot;Download Error&quot;, 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 = &quot;Percentage: &quot; + string.Format(&quot;{0}% ({1})&quot;, e.ProgressPercentage, FormatDataSpeed(speed)); label13.Text = &quot;Download Speed: &quot; + string.Format(&quot;{0} of {1} ({2})&quot;, 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 = &quot;Download cancelled&quot;; MessageBox.Show(&quot;The download was cancelled before completion.&quot;, &quot;Download Cancelled&quot;, MessageBoxButtons.OK, MessageBoxIcon.Information); } else if (e.Error != null) { MessageBox.Show(e.Error.ToString(), &quot;Download Error&quot;, MessageBoxButtons.OK, MessageBoxIcon.Error); } else { label14.Text = &quot;100%&quot;; label13.Text = &quot;Download complete&quot;; unzip(); //MessageBox.Show(&quot;The download completed successfully.&quot;, &quot;Download Complete&quot;, 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下载崩溃问题

本文发布于:2023-11-12 01:33:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580134.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WebClient

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!