# Problem implementing runTaskWithProgressBar(te::ThreadPoolJobWithProgress& job)

**URL:** <https://forum.juce.com/t/problem-implementing-runtaskwithprogressbar-te-threadpooljobwithprogress-job/37405>\
**Category:** Tracktion Engine\
**Created:** [January 31, 2020, 4:55pm UTC](https://forum.juce.com/t/problem-implementing-runtaskwithprogressbar-te-threadpooljobwithprogress-job/37405 "2020-01-31T16:55:00Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![RolandMR](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rolandmr/32/641_2.png) [@RolandMR](https://forum.juce.com/u/RolandMR)\
**Post date:** [January 31, 2020, 6:30pm UTC](https://forum.juce.com/t/problem-implementing-runtaskwithprogressbar-te-threadpooljobwithprogress-job/37405/2 "2020-01-31T18:30:22Z")

</div>

You can’t call `job.runJob()` on the main thread, or your UI will not respond, as you are seeing. You need spawn a thread which calls `job.runJob()` in a loop.

Then `runTaskWithProgressBar` needs to wait until the thread is finished while pumping message loop.

Rough code to implement:

```auto
    void runTaskWithProgressBar (ThreadPoolJobWithProgress& t)
    {
        TaskRunner runner (t);

         while (runner.isThreadRunning())
             if (! MessageManager::getInstance()->runDispatchLoopUntil (10))
                 break;
    }

//==============================================================================
struct TaskRunner : public Thread
{
    TaskRunner (ThreadPoolJobWithProgress& t) : Thread (t->getJobName()), task (*t)
    {
        startThread (4);
    }

    ~TaskRunner()
    {
        task.signalJobShouldExit();
        waitForThreadToExit (10000);
    }

    void run() override
    {
        while (! threadShouldExit())
            if (task.runJob() == ThreadPoolJob::jobHasFinished)
                break;
    }

    ThreadPoolJobWithProgress& task;
};

```

You’ll need to add whatever updates your UI.

---

_[View the full topic](https://forum.juce.com/t/problem-implementing-runtaskwithprogressbar-te-threadpooljobwithprogress-job/37405)._
