You will have to move quite a few parts of your code from the secondary thread to the main thread. The wxWidgets documentation you refer to says it all:
When a wxProcess object is passed to wxExecute(), its OnTerminate() virtual method is called when the process terminates. This allows the program to be (asynchronously) notified about the process termination and also retrieve its exit status which is unavailable from wxExecute() in the case of asynchronous execution.
And below:
Currently wxExecute() can only be used from the main thread, calling this function from another thread will result in an assert failure in debug build and won't work.
So, you need to eliminate the need to call wxExecute
from the secondary thread. How exactly you should do this depends on your application, but it will probably involve the secondary thread sending a custom wxWidgets event to the main thread using wxQueueEvent
. The main thread then handles the event by calling wxExecute
in asynchronous mode and retrieving its result later on.
Now what to do with the result?
Ideally, you rework your application logic such that the secondary thread does not need the result but instead:
- the main thread handles it all by itself, -or-
- another secondary thread is started and handles it.
This will minimize the amount of synchronization you have to do, and thus reduce the probability of hard-to-find concurrency programming errors.