服务器端采用C#语法:
1.在Global.asax文件中导入命名空间
<%@ Import Namespace="System.Timers" %>
2.Global.asax文件中的Application_Start()方法内写如下代码:
System.Timers.Timer objTimer = new Timer();
objTimer.Interval = 时间; //这个时间单位毫秒,比如10秒,就写10000
objTimer.Enabled = true;
objTimer.Elapsed += new ElapsedEventHandler(objTimer_Elapsed);
3.Global.asax文件中添加一个方法
void objTimer_Elapsed(object sender, ElapsedEventArgs e)
{
//这个方法内实现你想做的事情。
//例如:修改Application的某一个值等等。
}
以上3步则可以在指定时间间隔执行这个objTimer_Elapsed()方法,即达到你要得效果
===================================================
using System;
using System.Timers;
namespace 定时器ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(TimeEvent);
// 设置引发时间的时间间隔 此处设置为1秒(1000毫秒)
aTimer.Interval = 1000;
aTimer.Enabled = true;
Console.WriteLine("按回车键结束程序");
Console.WriteLine(" 等待程序的执行......");
Console.ReadLine();
}
// 当时间发生的时候需要进行的逻辑处理等
// 在这里仅仅是一种方式,可以实现这样的方式很多.
private static void TimeEvent(object source, ElapsedEventArgs e)
{
// 得到 hour minute second 如果等于某个值就开始执行某个程序。
int intHour = e.SignalTime.Hour;
int intMinute = e.SignalTime.Minute;
int intSecond = e.SignalTime.Second;
// 定制时间; 比如 在10:30 :00 的时候执行某个函数
int iHour = 10;
int iMinute = 30;
int iSecond = 00;
// 设置 每秒钟的开始执行一次
if( intSecond == iSecond )
{
Console.WriteLine("每秒钟的开始执行一次!");
}
// 设置 每个小时的30分钟开始执行
if( intMinute == iMinute && intSecond == iSecond )
{
Console.WriteLine("每个小时的30分钟开始执行一次!");
}
// 设置 每天的10:30:00开始执行程序
if( intHour == iHour && intMinute == iMinute && intSecond == iSecond )
{
Console.WriteLine("在每天10点30分开始执行!");
}
}
}
}
昔日数据,国内商家,成立于2020年,主要销售湖北十堰和香港HKBN的云服务器,采用KVM虚拟化技术构架,不限制流量。当前夏季促销活动,全部首月5折促销,活动截止于8月11日。官方网站:https://www.xrapi.cn/5折优惠码:XR2021湖北十堰云服务器托管于湖北十堰市IDC数据中心,母鸡采用e5 2651v2,SSD MLC企业硬盘、 rdid5阵列为数据护航,100G高防,超出防...
Chia矿机,Spinservers怎么样?Spinservers好不好,Spinservers大硬盘服务器。Spinservers刚刚在美国圣何塞机房补货120台独立服务器,CPU都是双E5系列,64-512GB DDR4内存,超大SSD或NVMe存储,数量有限,机器都是预部署好的,下单即可上架,无需人工干预,有需要的朋友抓紧下单哦。Spinservers是Majestic Hosting So...
cloudcone经常性有特价促销VPS放出来,每次的数量都是相当有限的,为了方便、及时帮助大家,主机测评这里就做这个cloudcone特价VPS补货专题吧,以后每次放货我会在这里更新一下日期,方便大家秒杀!官方网站:https://cloudcone.com/预交费模式,需要充值之后方可使用,系统自动扣费!信用卡、PayPal、支付宝,均可付款购买!为什么说cloudcone值得买?cloudc...