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:

  • hThread Returned handle of the threaded subroutine.
  • SubroutineName The actual, unquoted name of subroutine to be threaded. Alternatively, SubroutineName can be a variable of type LPVOID that contains the target address of the threaded SubroutineName.

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:

  • None

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:

  • hThread Handle of the thread to be terminated. BCX_THREADKILL is a dangerous function that should only be used in the most extreme cases. See the TerminateThread section of your Win32 SDK or PSDK Reference help for more information.

BCX_THREADRESUME statement

Purpose: BCX_THREADRESUME resumes the execution of a previously suspended subrotine thread.


 Syntax:

 BCX_THREADRESUME(hThread)

 Parameters:

  • hThread Handle of the thread to be resumed.

BCX_THREADSUSPEND statement

Purpose: BCX_THREADSUSPEND suspends the specified thread.


 Syntax:

 BCX_THREADSUSPEND(hThread)

 Parameters:

  • hThread Handle of the thread to be suspended.

BCX_THREADWAIT statement

Purpose: BCX_THREADWAIT waits for the thread, identified by its argument, to finish processing.


 Syntax:

 BCX_THREADWAIT(hThread)

 Parameters:

  • hThread Handle of the thread for which to wait.

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