Multi-threaded wxWidgets application

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
deepti
Experienced Solver
Experienced Solver
Posts: 88
Joined: Tue Jul 17, 2018 5:38 pm

Multi-threaded wxWidgets application

Post by deepti » Thu Jan 24, 2019 2:35 pm

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!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3257
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Multi-threaded wxWidgets application

Post by ONEEYEMAN » Thu Jan 24, 2019 3:50 pm

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.

Post Reply