]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/threadh.tex
fixed corrupted file, checked in as text file now
[wxWidgets.git] / docs / latex / wx / threadh.tex
1 \section{\class{wxThreadHelper}}\label{wxthreadhelper}
2
3 The wxThreadHelper class is a mix-in class that manages a single background
4 thread. By deriving from wxThreadHelper, a class can implement the thread
5 code in its own \helpref{wxThreadHelper::Entry}{wxthreadhelperentry} method
6 and easily share data and synchronization objects between the main thread
7 and the worker thread. Doing this prevents the awkward passing of pointers
8 that is needed when the original object in the main thread needs to
9 synchronize with its worker thread in its own wxThread derived object.
10
11 For example, \helpref{wxFrame}{wxframe} may need to make some calculations
12 in a background thread and then display the results of those calculations in
13 the main window.
14
15 Ordinarily, a \helpref{wxThread}{wxthread} derived object would be created
16 with the calculation code implemented in
17 \helpref{wxThread::Entry}{wxthreadentry}. To access the inputs to the
18 calculation, the frame object would often to pass a pointer to itself to the
19 thread object. Similiarly, the frame object would hold a pointer to the
20 thread object. Shared data and synchronization objects could be stored in
21 either object though the object without the data would have to access the
22 data through a pointer.
23
24 However, with wxThreadHelper, the frame object and the thread object are
25 treated as the same object. Shared data and synchronization variables are
26 stored in the single object, eliminating a layer of indirection and the
27 associated pointers.
28
29 \wxheading{Derived from}
30
31 None.
32
33 \wxheading{Include files}
34
35 <wx/thread.h>
36
37 \wxheading{See also}
38
39 \helpref{wxThread}{wxthread}
40
41 \latexignore{\rtfignore{\wxheading{Members}}}
42
43 \membersection{wxThreadHelper::wxThreadHelper}\label{wxthreadhelperctor}
44
45 \func{}{wxThreadHelper}{\void}
46
47 This constructor simply initializes a member variable.
48
49 \membersection{wxThreadHelper::m\_thread}
50
51 \member{wxThread *}{m\_thread}
52
53 the actual \helpref{wxThread}{wxthread} object.
54
55 \membersection{wxThread::\destruct{wxThreadHelper}}
56
57 \func{}{\destruct{wxThreadHelper}}{\void}
58
59 The 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
65 Creates a new thread. The thread object is created in the suspended state, and you
66 should call \helpref{GetThread()->Run()}{wxthreadrun} to start running
67 it. You may optionally specify the stack size to be allocated to it (Ignored on
68 platforms that don't support setting it explicitly, eg. Unix).
69
70 \wxheading{Return value}
71
72 One 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
85 This is the entry point of the thread. This function is pure virtual and must
86 be implemented by any derived class. The thread execution will start here.
87
88 The returned value is the thread exit code which is only useful for
89 joinable threads and is the value returned by
90 \helpref{GetThread()->Wait()}{wxthreadwait}.
91
92 This function is called by wxWidgets itself and should never be called
93 directly.
94
95 \membersection{wxThreadHelper::GetThread}\label{wxthreadhelpergetthread}
96
97 \func{wxThread *}{GetThread}{\void}
98
99 This is a public function that returns the \helpref{wxThread}{wxthread} object
100 associated with the thread.
101