悬赏分:5 浏览:301 次
|
用C#的定时器就可以实现。你可以1个小时轮询一次。轮询到的时候,再判断当前时间是否为周一或者是否为零点,如果是的话,则执行任务,否的话则跳过。 quartz.net 用c#的Timer,最好还是做成服务 楼主有言在先,虚拟主机,上面的都不用想了 其实“每周周一零点”,对于用户来说,这个时间可能根本不存在,你要做的只是在“每周周一零点”之后第一个访问者来之前做这个就可以了 这就比较简单了,在页面中判断当前时间和是否本次执行已经完了,如果恰好时间到了,又没执行过,那就执行了再显示 也就是你定的那个点后面第一个访问的人成了你程序的触发器,可能他的访问速度会比别人慢一点点,活该他倒霉,哈哈,所以你最好设在一个人少的时间 Windows定时任务~~ 可以做成一个服务, 使用定时任务去触发它~~ 设置线程Sleep的时间 Timer来监视,看个MSDN上的例子吧 using System; using System.Threading; class TimerExample { static void Main() { AutoResetEvent autoEvent = new AutoResetEvent(false); StatusChecker statusChecker = new StatusChecker(10); // Create the delegate that invokes methods for the timer. TimerCallback timerDelegate = new TimerCallback(statusChecker.CheckStatus); // Create a timer that signals the delegate to invoke // CheckStatus after one second, and every 1/4 second // thereafter. Console.WriteLine("{0} Creating timer.\n", DateTime.Now.ToString("h:mm:ss.fff")); Timer stateTimer = new Timer(timerDelegate, autoEvent, 1000, 250); // When autoEvent signals, change the period to every // 1/2 second. autoEvent.WaitOne(5000, false); stateTimer.Change(0, 500); Console.WriteLine("\nChanging period.\n"); // When autoEvent signals the second time, dispose of // the timer. autoEvent.WaitOne(5000, false); stateTimer.Dispose(); Console.WriteLine("\nDestroying timer."); } } class StatusChecker { int invokeCount, maxCount; public StatusChecker(int count) { invokeCount = 0; maxCount = count; } // This method is called by the timer delegate. public void CheckStatus(Object stateInfo) { AutoResetEvent autoEvent = (AutoResetEvent)stateInfo; Console.WriteLine("{0} Checking status {1,2}.", DateTime.Now.ToString("h:mm:ss.fff"), (++invokeCount).ToString()); if(invokeCount == maxCount) { // Reset the counter and signal Main. invokeCount = 0; autoEvent.Set(); } } } |