Page 1 of 1

Multi-threaded wxWidgets application

Posted: Thu Jan 24, 2019 2:35 pm
by deepti
Hi All,

I have a wxDialog instance, which has a few buttons like "Remove", "Disable" etc.
On click of each of these buttons, i need to start a thread, which does some time-consuming calculations (file size etc).
When the thread finishes execution, it needs to post an event, which will be handled by my wxDialog instance. This is will then update some UI controls to show the result of the calculation.
And on close of the dialog, all the worker threads should be deleted/quit in whatever state they are in (need not complete the calculations).

I did go through the documentation in the link below:
https://docs.wxwidgets.org/3.1/classwx_thread.html

But in my scenario, i will not know in advance how many threads are required to be created.
I need to create them on-the-fly, on click of a button. How can i achieve this?

Can we not use std::thread to create a thread, and then do a wxQueueEvent(handler, event.Clone()) from that regular thread? Does it have to be a wxThread? ( - where "handler" is the dialog class instance)

Please help!

Re: Multi-threaded wxWidgets application

Posted: Thu Jan 24, 2019 3:50 pm
by ONEEYEMAN
Hi,
It does not matter what type of thread you create - wxThread or std::thread.
And most programs does not know how many threads will be running at any given time.

What is essentials is the mechanism you use and the API.
Also, make sure you don't access any GUI from the secondary thread.

Thank you.