""" In this program, a separate execution context is created and run parallel to the main program using Threading. Simple ways to control this parallel execution are demonstrated via a few methods from the Threading API. The first step involves instantiating a Thread object using a suitable callback method. The callback used is an instance method of the Alpha class. This callback is passed as a single argument to the Thread constructor wrapped as a ThreadStart delegate. The thread then begins executing when the the `start` method is called. The main thread blocks (pauses) for 10 milliseconds via a call to the Thread.sleep method. During this pause the code in the callback will continue to execute. The main thread explicitly aborts the execution of `thr` via the `abort` method, then blocks until `thr` has exited through the use of the Join method. The code then attempts to restart the already aborted thread, at which point an exception will be thrown due to the thread already being terminated. Reference: http://msdn.microsoft.com/en-us/library/aa645740(VS.71).aspx Credit: Todd A. """ use System.Threading class Alpha def beta i = 0 while true print '[i]. Alpha.Beta is running in its own thread.' i += 1 class Simple def main print 'Thread Start/Stop/Join Sample' alpha = Alpha() thr = Thread(ThreadStart(ref alpha.beta)) # start running this thread. this will cause the beta method # to run parallel to this thread. thr.start # cause this thread to pause for 10 milliseconds Thread.sleep(10) thr.abort thr.join print print 'The beta method has finished running.' try print 'Try restarting the thread' thr.start catch e as ThreadStateException print '[e.getType] occurred while attempting to restart thread.' print 'This was expected because aborted threads are disposed.'