]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/threadh.tex
wxColour source cleaning. Corrections to 'const unsigned char' within wxColour docs.
[wxWidgets.git] / docs / latex / wx / threadh.tex
CommitLineData
78ee6a47
VZ
1\section{\class{wxThreadHelper}}\label{wxthreadhelper}
2
3The wxThreadHelper class is a mix-in class that manages a single background
4thread. By deriving from wxThreadHelper, a class can implement the thread
5code in its own \helpref{wxThreadHelper::Entry}{wxthreadhelperentry} method
6and easily share data and synchronization objects between the main thread
7and the worker thread. Doing this prevents the awkward passing of pointers
8that is needed when the original object in the main thread needs to
9synchronize with its worker thread in its own wxThread derived object.
10
11For example, \helpref{wxFrame}{wxframe} may need to make some calculations
12in a background thread and then display the results of those calculations in
13the main window.
14
15Ordinarily, a \helpref{wxThread}{wxthread} derived object would be created
16with the calculation code implemented in
17\helpref{wxThread::Entry}{wxthreadentry}. To access the inputs to the
18calculation, the frame object would often to pass a pointer to itself to the
dbd94b75 19thread object. Similarly, the frame object would hold a pointer to the
78ee6a47
VZ
20thread object. Shared data and synchronization objects could be stored in
21either object though the object without the data would have to access the
22data through a pointer.
23
24However, with wxThreadHelper, the frame object and the thread object are
25treated as the same object. Shared data and synchronization variables are
26stored in the single object, eliminating a layer of indirection and the
27associated pointers.
28
29\wxheading{Derived from}
30
31None.
32
33\wxheading{Include files}
34
35<wx/thread.h>
36
37\wxheading{See also}
38
a1d8baa9 39\helpref{wxThread}{wxthread}
78ee6a47
VZ
40
41\latexignore{\rtfignore{\wxheading{Members}}}
42
43\membersection{wxThreadHelper::wxThreadHelper}\label{wxthreadhelperctor}
44
45\func{}{wxThreadHelper}{\void}
46
47This constructor simply initializes a member variable.
48
6d06e061 49\membersection{wxThreadHelper::m\_thread}\label{wxthreadhelpermthread}
78ee6a47
VZ
50
51\member{wxThread *}{m\_thread}
52
53the actual \helpref{wxThread}{wxthread} object.
54
6d06e061 55\membersection{wxThreadHelper::\destruct{wxThreadHelper}}\label{wxthreadhelperdtor}
78ee6a47
VZ
56
57\func{}{\destruct{wxThreadHelper}}{\void}
58
59The destructor frees the resources associated with the thread.
60
61\membersection{wxThreadHelper::Create}\label{wxthreadhelpercreate}
62
63\func{wxThreadError}{Create}{\param{unsigned int }{stackSize = 0}}
64
65Creates a new thread. The thread object is created in the suspended state, and you
684761db 66should call \helpref{GetThread()->Run()}{wxthreadrun} to start running
78ee6a47
VZ
67it. You may optionally specify the stack size to be allocated to it (Ignored on
68platforms that don't support setting it explicitly, eg. Unix).
69
70\wxheading{Return value}
71
72One of:
73
74\twocolwidtha{7cm}
75\begin{twocollist}\itemsep=0pt
76\twocolitem{{\bf wxTHREAD\_NO\_ERROR}}{There was no error.}
77\twocolitem{{\bf wxTHREAD\_NO\_RESOURCE}}{There were insufficient resources to create a new thread.}
78\twocolitem{{\bf wxTHREAD\_RUNNING}}{The thread is already running.}
79\end{twocollist}
80
81\membersection{wxThreadHelper::Entry}\label{wxthreadhelperentry}
82
83\func{virtual ExitCode}{Entry}{\void}
84
85This is the entry point of the thread. This function is pure virtual and must
86be implemented by any derived class. The thread execution will start here.
87
88The returned value is the thread exit code which is only useful for
89joinable threads and is the value returned by
90\helpref{GetThread()->Wait()}{wxthreadwait}.
91
fc2171bd 92This function is called by wxWidgets itself and should never be called
78ee6a47
VZ
93directly.
94
95\membersection{wxThreadHelper::GetThread}\label{wxthreadhelpergetthread}
96
97\func{wxThread *}{GetThread}{\void}
98
99This is a public function that returns the \helpref{wxThread}{wxthread} object
100associated with the thread.
684761db 101