Hi,
I’m struggling with implementing the UIBehaviour::runTaskWithProgressBar(te::ThreadPoolJobWithProgress& job)
method for displaying a progress bar while rendering a track. The idea is to overlay the progress bar on top of the main component and updating it after every call to job.runJob()
. The problem is that the progress bar gets not displayed until the job is finished. My current workaround is to call MessageManager::getInstance()->runDispatchLoopUntil(1)
every few calls of job.runJob()
. This is however not a good way I think, but I’m not able to come up with a better solution. Can anyone maybe help out? Would be much appreciated.
My current code looks something like this:
void runTaskWithProgressBar(te::ThreadPoolJobWithProgress& job) override
{
if (auto topLevelWindow = dynamic_cast<ResizableWindow*>(TopLevelWindow::getActiveTopLevelWindow()))
{
if (auto component = dynamic_cast<MainComponent*>(topLevelWindow->getContentComponent()))
{
double progress = job.getCurrentTaskProgress();
component->ShowProgressBar(progress);
for (int i = 0; job.runJob() == ThreadPoolJob::jobNeedsRunningAgain; ++i)
{
progress = job.getCurrentTaskProgress();
if (i % 100 == 0)
MessageManager::getInstance()->runDispatchLoopUntil(1);
}
component->HideProgressBar();
}
}
}
Where component->ShowProgressBar(progress)
creates the ProgressBar, adds it and makes it visible and calls resized()
on the MainComponent, and component->HideProgressBar() destroys it and again calls resized()
.
Thanks in advance, greetings!