1  如何在asp.net服务器端,后台开一个计时器,每小时运行一次?
2  如何在客户端开个计时器,也是每小时运行一次?给我一个例题代码看行吗?谢了

解决方案 »

  1.   

    服务器端用
    下面的示例创建一个 Timer,它在十秒钟后在控制台上显示“Hello World!”(世界你好!)。
    [Visual Basic, C#, C++] 对于此示例,使用 System.Timers 命名空间。
    [Visual Basic] 
    Public Class Timer2
        
        Public Shared Sub Main()
            ' Create a new Timer with Interval set to 10 seconds.
            Dim aTimer As New System.Timers.Timer(10000)
            AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
            ' Only raise the event the first time Interval elapses.
            aTimer.AutoReset = False
            aTimer.Enabled = True
            
            Console.WriteLine("Press 'q' to quit the sample.")
            While Console.Read() <> CInt("q")
            End While
        End Sub    ' Specify what you want to happen when the event is raised.
        Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
            Console.WriteLine("Hello World!")
        End Sub
    End Class
    [C#] 
    public class Timer2
     {
     
         public static void Main()
         {
           // Create a new Timer with Interval set to 10 seconds.
           System.Timers.Timer aTimer = new System.Timers.Timer(10000);
           aTimer.Elapsed+=new ElapsedEventHandler(OnTimedEvent);
           // Only raise the event the first time Interval elapses.
           aTimer.AutoReset = false;
           aTimer.Enabled = true;
     
           Console.WriteLine("Press \'q\' to quit the sample.");
           while(Console.Read()!='q');
         }
     
         // Specify what you want to happen when the event is raised.
         private static void OnTimedEvent(object source, ElapsedEventArgs e) 
         {
           Console.WriteLine("Hello World!");
         }
     }
    自己改一下.客户端用
    javascriptfunction FunctionName()
    {
      要执行的东西
    }
    setInterval("FunctionName()",1000);
    后面的时间为毫秒
      

  2.   

    protected void Application_Start(Object sender, EventArgs e)
      {
       init();
       System.Timers.Timer myTimer=new System.Timers.Timer(3000); 
       //关联事件 
       myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
       myTimer.AutoReset = true ; 
       myTimer.Enabled = true ; 
      }  private void myTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
      {
       //获取当前时间 
       init();
      }
      
      private void init()
      {
       Application.Lock(); 
       Application["TIMEDEMO"]= DateTime.Now.ToString(); 
       Application.UnLock();
      }
      

  3.   

    2. window.setInterval(popmsg, 3600000);
       function popmsg()
       {
       }
      

  4.   

    如果要启动服务的时候就运用,那就把代码写在
    Global.asax里面就行了.
    protected void Application_Start(Object sender, EventArgs e)
    {
    System.Timers.Timer Timer1 = new System.Timers.Timer();
    Application["a"]=DateTime.Now.ToString();
    Timer1.Enabled = true;
    Timer1.Interval = 5000;
    Timer1.Elapsed += 
    new System.Timers.ElapsedEventHandler(Timer1_Elapsed);
    }
    private void Timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
    {
               Application["a"]=DateTime.Now.ToString();
     StreamWriter sw=File.AppendText(Server.MapPath("3.txt"));
    sw.WriteLine(Application["a"]);
    sw.Close();
                 

    }
      

  5.   

    我的意思就是想单独做一个服务器程序,这个怎么写,asp.net的可以吗,还是要写C#的应用?
      

  6.   

    直接写一个window services放到系统服务里去
      

  7.   

    Click the link to solve your problem.Good luck!