WPF:有没有一种简单的方法来创建进度窗口?

发布于 2024-08-21 16:18:27 字数 185 浏览 2 评论 0原文

我尝试创建一个,但一旦激活了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦罢 2024-08-28 16:18:27

您只需要获取 ProgressBar 调度程序。

您可以通过以下方式访问 ProgressBar

Window2.prograssbar.Dispatcher.Invoke(
    () => /*the code for modifying the progressbar*/ );

You just need to get the ProgressBar disptacher.

You can access the ProgressBar with:

Window2.prograssbar.Dispatcher.Invoke(
    () => /*the code for modifying the progressbar*/ );
滿滿的愛 2024-08-28 16:18:27

在 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.

不奢求什么 2024-08-28 16:18:27

您需要查看代表

You need to look into Delegates

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文