"""
A simple example of creating threads.

Note the use 'ref' to refer to a method instead of invoking it.
"""

use System.Threading


class ThreadExample

	var _maxSeconds = 1.2f
	var _start as DateTime

	def run
		_start = DateTime.now
		t = Thread(ref .writeB)
		t.start
		while not .isFinished
			print 'a' stop
		t.join
		print
		print 'Finished.'
		
	def writeB
		while not .isFinished
			print 'b' stop

	get isFinished as bool
		return DateTime.now.subtract(_start).totalSeconds >= _maxSeconds

	def main is shared
		ThreadExample().run
