Hi Michael,
In C++ it can be done with QThread. I have no examples, because the Qt/C++ apps that I work on are not open-source, but a rough outline is as follows:
First, derive a new thread class from QThread:
class MyUpdateThread : public QThread
{
Q_OBJECT
public:
// constructor
MyUpdateThread(vtkAlgorithm* alg, QObject* parent = nullptr);
// destructor
~MyUpdateThread();
protected:
// called when thread is started
void run() override;
private:
// the algorithm provided in the constructor
vtkAlgorithm* m_Algorithm;
};
The run()
method of this class should call the Update()
:
void MyUpdateThread::run()
{
m_Algorithm->Update();
}
Then your code starts the thread with myThread->start()
and checks it with myThread->isFinished()
, or waits for it with myThread->wait()
. Ideally the thread should also implement the abort()
method for when the thread must be shut down early.