Threaded DownloadFileAsync

184 views Asked by At

I might be very stupid but how to solve the following? When I want to download many files I use a list of links and threaded WebClient.DownloadFileAsync. But I want my UI to be updated (ProgressBar) during the process so I used this answer to partially solve the problem.

But when I apply this part of code

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());
        });
    }

I get the " 'System.Delegate' is a 'type' but is used like a 'variable' " error.

1

There are 1 answers

6
SLaks On BEST ANSWER

You can call Dispatcher.BeginInvoke() to run a delegate on the WPF UI thread.