我遇到一个问题,我想在每天下午2点运行函数send(),我创建了控件Timer1,但不知道怎么写代码,能指导我下怎么写代码吗?
还有就是另外一个函数get()要每过十天运行一次,我创建了空间Timer2,应该如何写代码?
谢谢了:)

解决方案 »

  1.   

    这个应该可以做成Windows Service的,我也不太会。
    提供一个笨方法:
    using System;
    using System.Timers;
    using System.Windows.Form;namespace DetailsTest
    {
        public class Test
        {
            static System.Timers.Timer t1 = new System.Timers.Timer();
            static Thread thread;
            public static void Main(string[] args)
            {
                Th();
                Form f = new Form();   //这里为了让程序一直停在这,显示了一个Form
                f.ShowDialog();        //如果本身是WinForm的就这个必要了
            }
            public static void Th()
            {
                t1.Interval = 1000;    //一秒钟一次
                t1.Elapsed += new ElapsedEventHandler(RestartTimer);
                t1.Enabled = true;
            }        public static void RestartTimer(object sender, ElapsedEventArgs e)
            {
                DateTime dt = DateTime.Now;
                if (dt.Hour == 14)            //判断当前时间是否为14点
                {
                    t1.Elapsed -= new ElapsedEventHandler(RestartTimer);
                    t1.Elapsed += new ElapsedEventHandler(Every24Hours);
                    t1.Interval = 3600 * 1000 * 24; //改成24小时一次
                    t1.Enabled = true;
                }
            }        public static void Every24Hours(object sender, ElapsedEventArgs e)
            {
                Console.WriteLine(DateTime.Now.ToString("hh-mm-ss"));
                send();
            }
            public static void send()
            {
            }
        }
    }