-2

我可能很愚蠢,但如何解决以下问题?当我想下载许多文件时,我使用链接列表和线程化的 WebClient.DownloadFileAsync。但我希望在此过程中更新我的 UI(ProgressBar),所以我使用这个答案来部分解决问题。

但是当我应用这部分代码时

void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
    {
        this.Dispatcher.BeginInvoke((Delegate MethodInvoker)
        {
            double bytesIn = double.Parse(e.BytesReceived.ToString());
            double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
            double percentage = bytesIn / totalBytes * 100;
            thebar.Value = int.Parse(Math.Truncate(percentage).ToString());
        });
    }

我得到“'System.Delegate' is a 'type' but is used like a 'variable'”错误。

4

1 回答 1

1

您可以调用Dispatcher.BeginInvoke()以在 WPF UI 线程上运行委托。

于 2014-11-30T16:09:50.570 回答