The wxThreadHelper class is a mix-in class that manages a single background thread. By deriving from wxThreadHelper, a class can implement the thread code in its own wxThreadHelper::Entry method and easily share data and synchronization objects between the main thread and the worker thread. Doing this prevents the awkward passing of pointers that is needed when the original object in the main thread needs to synchronize with its worker thread in its own wxThread derived object.
For example, wxFrame may need to make some calculations in a background thread and then display the results of those calculations in the main window.
Ordinarily, a wxThread derived object would be created with the calculation code implemented in wxThread::Entry. To access the inputs to the calculation, the frame object would often to pass a pointer to itself to the thread object. Similiarly, the frame object would hold a pointer to the thread object. Shared data and synchronization objects could be stored in either object though the object without the data would have to access the data through a pointer.
However, with wxThreadHelper, the frame object and the thread object are treated as the same object. Shared data and synchronization variables are stored in the single object, eliminating a layer of indirection and the associated pointers.
This constructor simply initializes a member variable.
wxThread * m_thread
the actual wxThread object.
The destructor frees the resources associated with the thread.
wxThreadError Create(unsigned int stackSize = 0)
Creates a new thread. The thread object is created in the suspended state, and you should call GetThread()->Run() to start running it. You may optionally specify the stack size to be allocated to it (Ignored on platforms that don't support setting it explicitly, eg. Unix).
|wxTHREAD_NO_ERROR||There was no error.|
|wxTHREAD_NO_RESOURCE||There were insufficient resources to create a new thread.|
|wxTHREAD_RUNNING||The thread is already running.|
virtual ExitCode Entry()
This is the entry point of the thread. This function is pure virtual and must be implemented by any derived class. The thread execution will start here.
The returned value is the thread exit code which is only useful for joinable threads and is the value returned by GetThread()->Wait().
This function is called by wxWidgets itself and should never be called directly.
wxThread * GetThread()
This is a public function that returns the wxThread object associated with the thread.