从另一个线程更新海燕中的进度条

发布于 2024-12-08 16:30:32 字数 188 浏览 2 评论 0原文

我正在尝试在 petrel 中开发一个多线程插件,其中我的算法在 2 个单独的线程中运行。该插件似乎工作正常,但我找不到任何更新进度栏的方法。

使用 Invoke 不会更新进度条(c# 进度条),并且我的 UI 在执行过程中完全冻结。

当算法运行时,有没有办法从另一个线程更新进度条(海燕进度或标准进度条)?

谢谢

I am trying to develop a multithreaded plugin in petrel where my algorithm runs in 2 separate threads. The plugin seems to work fine except I cant find any method to update the progress bar.

using Invoke does not update the progress bar(c# progress bar) and my UI completely freezes during execution.

Is there any way to update the progress bar (Either petrel progress or standard progresss bar) from another thread when the algo is running?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

断桥再见 2024-12-15 16:30:32

使用 Slb.Ocean.Petrel.PetrelLogger.NewAsyncProgress(String, ProgressType)NewAsyncProgress(String, ProgressType, AsyncProgressCanceledCallback, Object) 从后台线程更新进度条。

Use Slb.Ocean.Petrel.PetrelLogger.NewAsyncProgress(String, ProgressType) or NewAsyncProgress(String, ProgressType, AsyncProgressCanceledCallback, Object) to update the progress bar from background threads.

自由范儿 2024-12-15 16:30:32

仅当 UI 线程的消息处理未被阻止时,Control.Invoke 才起作用。如果您的主线程正在等待结果,您需要定期调用Application.DoEvents。

关于 Petrel 进度条:如果不允许用户交互,通常会使用简单的进度条,Petrel 会被阻塞直到操作完成,而如果最终用户开始某些操作但他能够在操作完成时使用一个或多个异步进度条,则使用一个或多个异步进度条操作在后台运行。

如果您选择第一种方法,您可以将进度存储在每个线程可见的变量中(确保该变量已正确锁定),并且主线程可以定期循环读取该变量并相应地更新进度。

Control.Invoke only works if the message processing of the UI thread is not blocked. If your main thread is waiting for the result you need to periodically call Application.DoEvents.

Regarding Petrel progress bars: Typically simple progress bar is used if no user interaction is allowed, Petrel is blocked until the operation is completed while one or more async progress bar is used if the end user starts some operation but he is able to work while the operation is running at the background.

If you choose the first approach you can e.g. store the progress in a variable which is visible to each thread (make sure the variable is properly locked) and the main thread can periodically read that variable in a loop and update progress accordingly.

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