C# 同时更新两个progressbar

C# 同时更新两个progressbar,c#,wpf,progress-bar,backgroundworker,C#,Wpf,Progress Bar,Backgroundworker,我有自动上传应用程序从ftp服务器和两个progressbar的更新整体和当前的下载状态。 第一个可以正常工作(update%=currentfileasint/allFilesToDownload*100%)。但我想上传当前下载的文件。 我的代码: 不幸的是,我仍然得到错误,我不能更新progressBar2,因为另一个进程使用它。 有什么办法吗? 谢谢通过dispatcher.BeginInvoke之类的方法更新值 Dispatcher.BeginInvoke(DispatcherPrior

我有自动上传应用程序从ftp服务器和两个progressbar的更新整体和当前的下载状态。 第一个可以正常工作(update%=currentfileasint/allFilesToDownload*100%)。但我想上传当前下载的文件。 我的代码:

不幸的是,我仍然得到错误,我不能更新progressBar2,因为另一个进程使用它。 有什么办法吗?
谢谢

通过dispatcher.BeginInvoke之类的方法更新值

Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(()=>
{
  progressbar2.value = newvalue;
}));
这将把您的工作推到主线程上,主线程保持Progressbar2

过程?你是说,对吧?
Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(()=>
{
  progressbar2.value = newvalue;
}));