WPF:有没有一种简单的方法来创建进度窗口?
我尝试创建一个,但一旦激活了 reportProgress,Window1 中的 BackgroundWorker
就无法访问 Window2 中的 ProgressBar
,因为“调用线程无法访问此对象,因为不同的线程线程拥有它”。
似乎我可以使用较低级别的线程模型,但它似乎也复杂得多。
I tried creating one, but the BackgroundWorker
in Window1 couldn't access the ProgressBar
in Window2 once the reportProgress was activated, because "The calling thread cannot access this object because a different thread owns it".
Seems there's a lower level thread model I could use, but it also seems a lot more complicated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需要获取
ProgressBar
调度程序。您可以通过以下方式访问
ProgressBar
:You just need to get the
ProgressBar
disptacher.You can access the
ProgressBar
with:在 WPF 中,UI 控件和属性只能从 UI 线程激活。为了从不同的线程更改进度条的值,您可以将命令添加到 GUI 线程的调度程序队列。您可以通过将委托传递给
Dispatcher.Invoke()
方法来完成此操作。请参阅 http://msdn.microsoft.com/en-us/ 中的文章magazine/cc163328.aspx 了解更多详情。In WPF, UI controls and properties may only be activated from the UI thread. In order to change the progress bar's value from a different thread, you can add a command to the GUI thread's dispatcher queue. You can do this by passing a delegate to the
Dispatcher.Invoke()
method. See the article at http://msdn.microsoft.com/en-us/magazine/cc163328.aspx for more details.您需要查看代表
You need to look into Delegates