'This demo increments a counter in a thread, which can be monitored from the console.

uses corewin
uses console
extern
'
class ThreadDemo
================
int counter
int running
sys thread
'
function constructor()
  counter=0
  running=1
  thread=CreateThread(0,0,@threadcall,@this,0,0)
end function
'
function destructor()
  CloseHandle(thread)
end function
'
function threadcall()
  while running
    act()
  wend
end function
'
function act()
  counter++
  sleep 20
end function
'
function stop()
  running=0
end function
'
end class
'
'TEST:
new ThreadDemo td()
int k
printl "Press [space] to show count, [enter] to close"
do
  k=waitkey
  select k
  case 3,13 : td.stop() : exit do
  case 32 : printl td.counter
  end select
loop
printl "Final count " td.counter
waitkey
del td
