从另一个线程更新海燕中的进度条
我正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
Slb.Ocean.Petrel.PetrelLogger.NewAsyncProgress(String, ProgressType)
或NewAsyncProgress(String, ProgressType, AsyncProgressCanceledCallback, Object)
从后台线程更新进度条。Use
Slb.Ocean.Petrel.PetrelLogger.NewAsyncProgress(String, ProgressType)
orNewAsyncProgress(String, ProgressType, AsyncProgressCanceledCallback, Object)
to update the progress bar from background threads.仅当 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.