createthread.bmx 764 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'Make sure to have 'Threaded build' enabled!
  2. '
  3. Strict
  4. 'Custom print that shows which thread is doing the printing
  5. Function MyPrint( t$ )
  6. If CurrentThread()=MainThread()
  7. Print "Main thread: "+t
  8. Else
  9. Print "Child thread: "+t
  10. EndIf
  11. End Function
  12. 'Our thread function
  13. Function MyThread:Object( data:Object )
  14. 'show data we were passed
  15. Myprint data.ToString()
  16. 'do some work
  17. For Local i=1 To 1000
  18. MyPrint "i="+i
  19. Next
  20. 'return a value from the thread
  21. Return "Data returned from child thread."
  22. End Function
  23. MyPrint "About to start child thread."
  24. 'create a thread!
  25. Local thread:TThread=CreateThread( MyThread,"Data passed to child thread." )
  26. 'wait for thread to finish and print value returned from thread
  27. MyPrint WaitThread( Thread ).ToString()