Reputation: 81
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
Upvotes: 1
Views: 350
Reputation: 685
Use Slb.Ocean.Petrel.PetrelLogger.NewAsyncProgress(String, ProgressType)
or NewAsyncProgress(String, ProgressType, AsyncProgressCanceledCallback, Object)
to update the progress bar from background threads.
Upvotes: 4
Reputation: 41
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.
Upvotes: 2