C# Backgroundworker 报告 2 个进度条的进度?
我正在处理几个大文件,并使用 backgroundWorker1.ReportProgress(percent)
来报告每个文件完成时的进度。但现在我想要第二个进度条来报告每个单独文件在处理时的进度(并重置下一个文件)。我可以使用正在读取的当前字节位置并除以文件的总大小来获取进度百分比。但是,如果只有一个 ProgressChanged 事件,如何将此值传递给 ProgressBar2 呢?
I have several large files that I'm processing and I'm using the backgroundWorker1.ReportProgress(percent)
to report the progress as each file is finished. But now I want to have a second progress bar to report the progress for each individual file as it's being processed (and resets for the next file). I can use the current byte position I'm reading from and divide by the total size of the file to get the progress in percentage. But how do I pass this value to progressBar2 if there's only one ProgressChanged event?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一种方法是使用 BackgroundWorker.ReportProgress(Int32, Object) 并传递您想要的任何内容,用户状态参数。
另一个方法是简单地知道,当第一个进度条达到 100% 时,您需要增加另一个进度条。
One way is to use BackgroundWorker.ReportProgress(Int32, Object) and pass whatever you want, in the userState parameter.
Another is to simply know that when you've reached 100% on the first progress bar you need to increment the other bar.
ReportProgress 有一个重载,它允许您传递额外的对象。您可以使用它来返回您需要的任何额外状态。
然后,您可以从
ProgressChangedEventArgs.UserState
。
ReportProgress has an overload which allows you to pass an extra object. You can use this to return any extra state you need.
You can then read the state from
ProgressChangedEventArgs.UserState
.