Search code examples
c++multithreadingboostvclboost-thread

How might one create an extra worker thread for a single threaded GUI application?


I am currently developing new features for an existing VCL application. The application creates charts and static images using a thirdparty package called TeeChart. There is one instance where I have to load in 2 million data points to create a static image chart. However, this takes a while to load and the user can't do anything in the application until it is completed. Therefore I would prefer to create a worker thread to process the data points so the GUI doesn't freeze.

The method setData() sets the following member variables, which the VCL component will then go on and use to create the Chart:

// Holds the Y position for the image (columns)
DynamicArray<double>* mpda_XValues;

// Holds the colour for the corresponding element in the x and y
// position
DynamicArray<double>* mpda_YValues;

// Holds the z position for the image (rows)
DynamicArray<double>* mpda_ZValues;

What things should I consider when creating a worker thread?

How might I create the thread using boost when all the data processing occurs in one method setData(){...}?


Solution

  • Since you are using the VCL, it might be a good idea to look at the TThread class. Create an inherited class from this, and use the Synchronize method when communicating with your main thread. You can try looking at: http://docwiki.embarcadero.com/VCL/en/Classes.TThread and http://docwiki.embarcadero.com/RADStudio/en/Defining_Thread_Objects