HTTP和FTP下载进度条processbar.value超出最大值

Sirios 2011-04-09 11:38:37
小弟有一事请教大家,最近在调试一个支持HTTP和FTP多线程下载工具,其中使用到processbar来显示下载进度,相同的算法HTTP下载时processbar.value值没有超出最大值(最大值为所要下载文件的大小),而FTP却下载到2/3的时候就出错并提示processbar.value超出最大值,我想当的郁闷,实在不知道问题出在哪里,浪费大家宝贵的时间帮帮小弟,谢谢大家!下面为相关代码:
public class InforClass
{
private static int threadcount;//线程数量
public static int[] threadPercent;//线程下载文件完成量
public static int[] threadisComplate;//线程下载文件是否完成
public static string msg = "下载文件开始";
public static int FileSize;//下载文件的大小;
public static DateTime startTime;//开始下载时间
public static int ThreadCount
{
get
{
return threadcount;
}
set
{
threadcount = value;
threadPercent = new int[threadcount];
for (int i = 0; i < threadcount; i++)
{
threadPercent[i] = 0;
}
threadisComplate = new int[threadcount];
for (int i = 0; i < threadcount; i++)
{
threadisComplate[i] = 0;
}
}
}
}



private void timer1_Tick(object sender, EventArgs e)
{
if (ftpfile != null)
{
int data = 0;
for (int i = 0; i < InforClass.ThreadCount; i++)
{
data += InforClass.threadPercent[i];
}
progressBar1.Maximum = InforClass.FileSize;
progressBar1.Value = data;
label5.Text = InforClass.msg;
TimeSpan AllTs = DateTime.Now - InforClass.startTime;//已下载文件的时间
double PByte = data / AllTs.TotalSeconds / 1024;//计算速度,byte/秒换算成KB/秒
if (InforClass.msg.IndexOf("正在下载") > 0)
{
label6.Text = string.Format("{0}KB/秒", (int)PByte);
}
else
{
label6.Text = "0KB/秒";
}

}
}
...全文
59 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
syz 2011-04-12
  • 打赏
  • 举报
回复
你的代码的确很蹩脚。*|-)
matrixcl 2011-04-10
  • 打赏
  • 举报
回复
ftp文件超过2G了吧?

progressBar1.Maximum
progressBar1.Value
均是int型,超过2G就溢出。

给processBar传值时单位缩小一下吧,例如都除以1025
xxiju203 2011-04-10
  • 打赏
  • 举报
回复
你这样写本身就有问题,把最大值设置为100,把下载进度算成百分百再传过去。
孟子E章 2011-04-10
  • 打赏
  • 举报
回复
data肯定是大于InforClass.FileSize了
Sirios 2011-04-10
  • 打赏
  • 举报
回复
多谢楼上,我下载的文件仅仅几十KB而已。。。

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧