0

好的,我有这个:

foreach (FileInfo fileinfo2 in Arquivos2)
{
    label8.Text = "Enviando(NFe): " + fileinfo2.Name + "...";
    label8.Update();
    WebClient client = new WebClient();
    client.Credentials = new System.Net.NetworkCredential(usuario, senha);
    client.UploadProgressChanged += new UploadProgressChangedEventHandler(UploadProgressCallback);
    client.UploadFile(new Uri("ftp://" + ftp + "/" + caminho + "//nf//" + fileinfo2.Name), "STOR", @"C:\\NFe\" + fileinfo2.Name);
    bar++;
    backgroundWorker1.ReportProgress(bar);
}

它工作正常,但我有:

private void UploadProgressCallback(object sender, UploadProgressChangedEventArgs e)
{
    progressBar2.Value = e.ProgressPercentage;
    progressBar2.Update();
}

并且progressBar2没有任何反应......

如何使用上传进度更新我的 progressBar2?我不能将 UploadFile 与 UploadProgressChanged 一起使用?

4

1 回答 1

2

根据http://msdn.microsoft.com/en-us/library/system.net.webclient.uploadprogresschanged.aspx

每次异步上传进行时都会引发此事件。

它仅由 3 个异步事件引发。您正在调用的版本是一个阻塞方法,在它完成之前不会返回并且不会引发进度事件。

于 2013-03-28T22:45:19.417 回答