To start a thread within a process, use either INonGUIThread or IThread to represent the thread. Pass the code you want the thread to run to either the thread's constructor or to its start() method. You can wrap your thread code as a global function, as a class method, or as an object reference.
These examples pass a user-defined function, threadedFunction(), to a thread to run when it calls start(). Functions passed to thread constructors must be declared to be of type _Optlink or type _System (_Optlink and _System functions return void).
void _Optlink myThreadedFunction()
{
// Your code, to be executed in the new thread, goes here.
}
If you want to thread a function that has arguments:
void* threadArgs;
The following examples illustrate how to launch a thread to run your user-defined method:
void main(){
INonGUIThread myThread(myThreadedFunction, threadArgs);
...
myThread.start();
}
void main(){
IIThread *myThread = new IIThread();
...
myThread->start(myThreadedFunction, threadArgs);
}
// Assume myThreadFn is a subclass of IThreadFn
IThread myThread(myThreadFn,threadArgs);
...
myThread.start();
// myThread.start() automatically executes myThreadFn::run()
IThread myThread();
...
// Assume myThreadFn is a subclass of IThreadFn
myThread.start(myThreadFn,threadArgs);
// myThread.start() automatically executes myThreadFn::run()