我需要在 DoWork 事件之外更改我的后台工作人员进度,这可能吗?
我的代码
private void progress_changed(string fileName, DownloadProgressChangedEventArgs e)
{
progress = e.ProgressPercentage;
Filename = fileName;
// change the progress here
}
private void worker_DoWork(string fileName)
{
WebClient client = new WebClient();
client.DownloadProgressChanged += (obj, e) => progress_changed(fileName, e);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(progress_complete);
client.DownloadFileAsync(new Uri(Link), Savepath);
}
private void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
mainForm.dlist.Items[mainForm.dlist.Items.IndexOfKey(Filename)].SubItems[2].Text = progress.ToString() + "%";
mainForm.dlist.Items[mainForm.dlist.Items.IndexOfKey(Filename)].SubItems[3].Text = "Downloading";
}