我在Global.asax中定义了一个定时器,当检测到Application["State"]="True"时通知主页面去执行相应的过程,麻烦各位?

解决方案 »

  1.   

    这个简单.参看一下Global.asax中定时器的写法就行了.
      

  2.   

    首先在 global.asax 中的 Application_OnStart 事件过程中定义计时器,代码如下:
    [VB.NET] global.asax
    <%@ import Namespace="System.Timers" %> 
    <script runat="server">    Sub Application_OnStart(sender As Object, e As EventArgs) 
           ' 创建一个计时器,单位:毫秒
           Dim aTimer As New System.Timers.Timer(10000)       ' 将 Fresher 指定为计时器的 Elapsed 事件处理程序 
           AddHandler aTimer.Elapsed, AddressOf Fresher        ' AutoReset 属性为 true 时,每隔指定时间循环一次; 
           ' 如果为 false,则只执行一次。 
           aTimer.AutoReset = True 
           aTimer.Enabled = True 
             
           ' 先给 Application("TimeStamp") 指定一个初值 
           Application.Lock() 
           Application("TimeStamp") = DateTime.Now.ToString() 
           Application.UnLock() 
       End Sub    Sub Fresher(sender As Object, e As ElapsedEventArgs) 
           Application.Lock() 
           Application("TimeStamp") = DateTime.Now.ToString() 
           Application.UnLock() 
       End Sub </script>
    从网上找来的,如果需要,我可以帮你改成C#
      

  3.   

    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)
        {
            localhost.WebService a = new localhost.WebService();
            string s = a.HelloWorld();
        }
    这里还有一个,也是从网上找来的!!
      

  4.   

    vam_ma,你好,首先谢谢你!
    你上面说的定时器我知道。
    我是说要通知到例如Default.aspx这样的页面上执行,因为它与Global.asax不再同一个线程里!
    不知你又没有好的解决办法??
      

  5.   

    放在default.aspx是一样的,即使用户不在这个页面了,只要他曾经调用过这个页面
    都会执行定时器的事件