try
{
//点击下载
string str = this.listView1.SelectedItems[0].Text;
string str1 = this.listView1.SelectedItems[0].SubItems[2].Text;
string str2 = str + "\\" + str1;
ThreadStart st = new ThreadStart(delegate()
{
WebClient web = new WebClient();
web.Credentials = new NetworkCredential("caojian", "kancuo1");
web.DownloadFile("ftp://172.28.37.34/" + str1 + "/" + str, dir + "/" + str);
});
Thread tt = new Thread(st);
tt.Start();
MessageBox.Show("下载完成");
}
catch (Exception)
{
MessageBox.Show("下载失败,请联系
管理员检查服务器运行状态");
}
请问我怎么才能智能判断下载是否完成呢?现在只要点了下载就提示完成了
WebClient ws = new WebClient();
//绑定下载事件,显猜册示当前进度
ws.DownloadProgressChanged += new DownloadProgressChangedEventHandler(OnDownloadProgressChanged);
//绑定下载完成事件,进行枯山完成提示
ws.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileCompleted);
ws.DownloadFileAsync下载,然后在事件里处理进度没兆中和完成通知
在tt.start();后加一行
while (tt.IsAlive) { Application.DoEvents(); }