BCX_THREAD function
Purpose: BCX_THREAD returns a handle to a thread that begins execution of a subroutine. It must be a subroutine, it can not be a function.
Syntax: hThread = BCX_THREAD(SubroutineName) Parameters:
|
Example:
DIM MySubPtr AS LPVOID DIM hMyThread AS HANDLE MySubPtr = SUB1 hMyThread = BCX_THREAD(MySubPtr) BCX_THREADWAIT(hMyThread) SUB SUB1 FOR INTEGER i = 1 to 1000 PRINT i NEXT END SUB
BCX_THREADEND statement
Purpose: BCX_THREADEND ends the thread created by BCX_THREAD.
Syntax:
BCX_THREADEND
Parameters:
|
Remarks: Place a BCX_THREADEND statement immediately before your END SUB and EXIT SUB statements within your threaded subroutines.
Example:
SUB MyThread LOCAL Foo Foo = Foo + 1 IF Foo > 10 THEN PRINT "Exiting Thread Programmatically" BCX_THREADEND EXIT SUB END IF BCX_THREADEND END SUB
BCX_THREADKILL statement
Purpose: BCX_THREADKILL terminates a thread.
Syntax: BCX_THREADKILL(hThread) Parameters:
|
BCX_THREADRESUME statement
Purpose: BCX_THREADRESUME resumes the execution of a previously suspended subrotine thread.
Syntax: BCX_THREADRESUME(hThread) Parameters:
|
BCX_THREADSUSPEND statement
Purpose: BCX_THREADSUSPEND suspends the specified thread.
Syntax: BCX_THREADSUSPEND(hThread) Parameters:
|
BCX_THREADWAIT statement
Purpose: BCX_THREADWAIT waits for the thread, identified by its argument, to finish processing.
Syntax: BCX_THREADWAIT(hThread) Parameters:
|
Example:
'*************************************************************** ' Begin Sample BCX_THREAD Application '*************************************************************** DIM hThread[3] AS HANDLE hThread[0] = BCX_THREAD(SUB1) hThread[1] = BCX_THREAD(SUB2) hThread[2] = BCX_THREAD(SUB3) SLEEP(2000) : COLOR 4,0 : PRINT " SUB3: Suspending" BCX_THREADSUSPEND(hThread[2]) SLEEP(10000) : COLOR 4,0 : PRINT " SUB3: Resuming " SLEEP(2000) BCX_THREADRESUME(hThread[2]) SLEEP(4000) : COLOR 4,0 : PRINT " SUB3: Cancelled!" BCX_THREADKILL(hThread[2]) FOR INTEGER i = 0 TO 2 BCX_THREADWAIT(hThread[i]) NEXT COLOR 15,0 PRINT "Press Any Key To END" KEYPRESS SUB SUB1 DIM I FOR I = 1 TO 50 COLOR 2,0 PRINT " SUB #1 = ";I; SLEEP(500) NEXT COLOR 2,0 PRINT " " : PRINT " SUB #1 Completed!" BCX_THREADEND END SUB SUB SUB2 DIM I FOR I = 1 TO 50 COLOR 3,0 PRINT " SUB #2 = ";I; SLEEP(400) NEXT COLOR 3,0 PRINT " " : PRINT " SUB #2 Completed!" BCX_THREADEND END SUB SUB SUB3 DIM I FOR I = 1 TO 50 COLOR 4,0 PRINT " SUB #3 = ";I SLEEP(300) NEXT COLOR 4,0 PRINT " " : PRINT " SUB #3 Completed!" BCX_THREADEND END SUB