续:JScript.NET学习历程(例程) 利用JScript.NET和.NET类库创建线程。
http://blog.csdn.net/runmin/archive/2004/08/13/74038.aspx
/*
* Compile sample:
* jsc /t:exe /out:Threading.exe Threading.js
*/
//
// Using directives
//
import System;
import System.Threading;
import System.Windows.Forms;
// the thread
var theThread : WriteConsoleThread = new WriteConsoleThread();
// standard thread
Application.Run(new Form());
// stop the thread
theThread.StopThread = true;
// thread runner class
class WriteConsoleThread
{
// thread start
private var threadStart : ThreadStart;
// thread
public var SingleThread : Thread;
// stop flag
public var StopThread : boolean;
// Constructor
public function WriteConsoleThread()
{
this.StopThread = false;
this.threadStart = printDot;
this.SingleThread = new Thread(this.threadStart);
this.SingleThread.Start();
}
// print '.' to console screen
private function printDot()
{
while (!this.StopThread)
{
Console.Write(".");
Thread.Sleep(1000);
}
Console.WriteLine("");
Console.Write("Stopping thread...");
this.SingleThread.Abort();
}
}