使用JScript.NET製作asp.net網頁基礎教程5
來源:互聯網
上載者:User
Jscript.net可以用JScript 或任意NET 架構語言(如 C #,VB7.0) 通過增加extends主題詞在類聲明以後來繼承和擴充現有類。這能力允許Jscript.net非常容易地利用 NET 平台的豐厚資源。為了說明這些,給出一個程式。這個程式擴充了NET 架構的ServiceBase 類。
// 匯入需要的.net命名空間
import System;
import System.ServiceProcess;
import System.Diagnostics;
import System.Timers;
class SimpleService extends ServiceBase
{
private var timer : Timer;
function SimpleService()
{
CanPauseAndContinue = true;
ServiceName = "JScript Service";
timer = new Timer();
timer.Interval = 1000;
timer.AddOnTimer(OnTimer);
}
protected override function OnStart(args : String[])
{
EventLog.WriteEntry("JScript Service started");
timer.Enabled = true;
}
protected override function OnStop()
{
EventLog.WriteEntry("JScript Service stopped");
timer.Enabled = false;
}
protected override function OnPause()
{
EventLog.WriteEntry("JScript Service paused");
timer.Enabled = false;
}
protected override function OnContinue()
{
EventLog.WriteEntry("JScript Service continued");
timer.Enabled = true;
}
function OnTimer(source : Object, e : EventArgs)
{
EventLog.WriteEntry("Hello World from JScript!");
}
}
ServiceBase.Run(new SimpleService());