ID    Time TimeOut
1     2011-11-16 07:00:00 25
2     2011-11-16 15:30:00 32
3     2011-11-16 18:36:00 24
4     2011-11-17 11:23:00 8话不多说,上面是一个表,想要做的东西是在Global里开启个线程,让它半小时或一小时自动执行一次,拿当前时间去表中历遍Time字段的时间比较,相减后datediff(hh,Time,getdate())相减的时间小于报警时间(TimeOut)2个小时的话就自动在页面提示用户。怎么实现?谢谢!

解决方案 »

  1.   

    Application_Start事件方法里用System.Timers.Timer类,自己研究一下。
      

  2.   

    通过在网站的Global.asax的Application_Start方法中加入定时器 定时调用WebService来做吧。
    该WebService的一个方法 负责在后台处理当前时间和你的那个表中的数据比较,相减后datediff(hh,Time,getdate())相减的时间小于报警时间(TimeOut)2个小时的话就自动在页面提示用户
    <%@ Application Language="C#" %><script runat="server">
       
        void Application_Start(object sender, EventArgs e)
        {
            // 在应用程序启动时运行的代码
            System.Timers.Timer myTimer = new System.Timers.Timer(60000);
            myTimer.Elapsed += new System.Timers.ElapsedEventHandler(OnTimedEvent);
            myTimer.Interval = 60000;
            myTimer.Enabled = true;
        }
       
        private static void OnTimedEvent(object source, System.Timers.ElapsedEventArgs e)
        {
            //调用WebService,然后获取报警提示信息
            localhost.WebService a = new localhost.WebService();
            Application["tips"] = a.HelloWorld();
        }
       
        void Application_End(object sender, EventArgs e)
        {
            //  在应用程序关闭时运行的代码
        }
           
        void Application_Error(object sender, EventArgs e)
        {
            // 在出现未处理的错误时运行的代码
        }    void Session_Start(object sender, EventArgs e)
        {
            // 在新会话启动时运行的代码
        }    void Session_End(object sender, EventArgs e)
        {
            // 在会话结束时运行的代码。
            // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
            // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
            // 或 SQLServer,则不会引发该事件。
        }
          
    </script>
    至于如何将Application["tips"]这个信息如何以消息窗口显示,这儿太多例子了,你参考:
    http://jackyrong.iteye.com/blog/238868