【发布时间】:2014-09-16 12:17:31
【问题描述】:
我正在用 C# 编写一个更新程序,我现在需要一些帮助(我是这种语言的新手,请解释你的提示:D)
我的代码:
System.IO.Directory.CreateDirectory("tmp");
int mmx = updnec.Count();
label6.Text = "0/" + mmx;
MessageBox.Show(label6.Text);
int mmn = 0;
foreach (string lz in link)
{
MessageBox.Show(lz);
client.DownloadFileAsync(new Uri(lz), "tmp/update00" + mmn + ".exe");
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
label6.Text = mmn + "/" + mmx;
mmn = +1;
//Whithout that while{} - part, it tries to download all links from the list at once. But I don't want the program to do that. I don't want it to show a message all the time, too, but when i leave that while{} - part empty, the program just freezes and doesn't even download.
while (progressBar1.Maximum != progressBar1.Value)
{
MessageBox.Show("Test");
}
}
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Maximum = (int)e.TotalBytesToReceive;
progressBar1.Value = (int)e.BytesReceived;
string sysload = progressBar1.Value /1000000 + "/" + progressBar1.Maximum /1000000 + " MB geladen";
label12.Text = sysload;
}
请阅读我的代码中的评论。
如何解决我的问题!?请帮帮我!
重新设计
编辑:
label11.Text = System.DateTime.Now.ToString();
backgroundWorker1.RunWorkerAsync(link);
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
List<string> lz = (List<string>)e.Argument;
int mmn = 0;
progressBar1.Style = ProgressBarStyle.Blocks;
System.IO.Directory.CreateDirectory("tmp");
int mmx = 10;
label6.Text = "0/" + mmx;
foreach (string lkz in lz)
using (var client = new WebClient())
{
MessageBox.Show("Hallo" + lkz);
client.DownloadFile(lkz, "tmp/update00" + mmn + ".exe");
}
}
【问题讨论】:
-
您可以做的是将文件压缩成一个zip文件并将该zip文件发送给客户端。我认为没有其他方法可以做到这一点。查看以下链接了解更多信息
-
为什么不包括一个问题而不是一个阅读 cmets 的说明?寻求调试帮助的问题必须在问题本身中包含特定问题。
-
@MoezRebai 这对我来说是不可能的:D
-
@Sayse 向您展示我的问题。
-
@Sayse 在评论部分(“//”部分)是我的问题。 Quote: 尽管{} - 部分,它尝试一次下载列表中的所有链接。但我不希望程序这样做。我也不希望它一直显示消息,但是当我将其留空时,{} - 部分为空,程序就会冻结,甚至无法下载。