如何写一个服务,实现定期将数据库表的数据写到另一个表中.

解决方案 »

  1.   

    做一个服务器来做,是不是不大好??
    要么用异步,要么用Timer
      

  2.   

    不用服务?
    那我是不是要打开网页才能执行Timer啊!
      

  3.   

    那就做成WINFORM程序,开个线程一直RUN着就可以了~
      

  4.   

    作成Windows 服务不行吗?作成winform每次得调用才行啊。
      

  5.   

    using System;
    using System.ServiceProcess;
    using System.Diagnostics;
    using System.Timers;public class SimpleService: ServiceBase {
        protected Timer timer;    public static void Main() {
            ServiceBase.Run(new SimpleService());
        }    public SimpleService()
        {
            CanPauseAndContinue = true;
            ServiceName = "Hello-World 服务";        timer = new Timer();
            timer.Interval = 1000;
            timer.Elapsed += new ElapsedEventHandler(OnTimer);
        }    protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry("Hello-World 服务已启动");
            timer.Enabled = true;
        }    protected override void OnStop()
        {
            EventLog.WriteEntry("Hello-World 服务已停止");
            timer.Enabled = false;
        }    protected override void OnPause()
        {
            EventLog.WriteEntry("Hello-World 服务已暂停");
            timer.Enabled = false;
        }    protected override void OnContinue()
        {
            EventLog.WriteEntry("Hello-World 服务已继续");
            timer.Enabled = true;
        }    protected void OnTimer(Object source, ElapsedEventArgs e)
        {
            EventLog.WriteEntry("Hello World!");
        }
    }