c# 任务调度器

 class Program
    {
        public static ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
        private static int INTERVAL = 300000;
        //private DateTime lastTime = DateTime.Now;
        private static System.Timers.Timer aTimer = new System.Timers.Timer();
        public string ftpServer = "";
        public string Name = "";
        public string PWD = "";
        public RunDownloadTask mail = new RunDownloadTask();
        public static Dictionary<int, string> mailTextList = new Dictionary<int, string>();
        static void Main(string[] args)
        {
            Program pro = new Program();
            aTimer.Elapsed += new ElapsedEventHandler(pro.TimerRun);
            aTimer.Enabled = true;
            Console.WriteLine("按回车结束");
            Console.ReadLine();
        }
        private void TimerRun(object source, ElapsedEventArgs e)
        {
            log.Info("TimerRrun-Time:" + DateTime.Now);
            aTimer.Interval = 5 * 60 * 1000;
            ThreadPool.SetMaxThreads(30, 30);
            DateTime time=DateTime.Now;
            mail.EmailSend(time);
            List<DownloadReportHistory> reportHistory = DownlodReportManager.GetTaskByDay(Convert.ToDateTime(time.ToString("yyyy-MM-dd")), (int)EnumTaskStatus.UnRunning);

            foreach (DownloadReportHistory his in reportHistory)
            {
                DownlodReportManager downloadM = new DownlodReportManager();
                ThreadPool.QueueUserWorkItem(new WaitCallback(downloadM.DoWork), his);
                //Thread.Sleep(8000);
                int MaxWorkerThreads, miot, AvailableWorkerThreads, aiot;

                //获得最大的线程数量  
                ThreadPool.GetMaxThreads(out MaxWorkerThreads, out miot);
                log.Info("获得最大的线程数量" + MaxWorkerThreads);
                AvailableWorkerThreads = aiot = 0;

                //获得可用的线程数量  
                ThreadPool.GetAvailableThreads(out AvailableWorkerThreads, out aiot);
                log.Info("获得可用的线程数量" + AvailableWorkerThreads);
                //返回线程池中活动的线程数  
                int result = MaxWorkerThreads - AvailableWorkerThreads;
                log.Info("返回线程池中活动的线程数:" + result);
            }
            log.Info("TimerRrunEnd-Time:" + DateTime.Now);

            Thread.Sleep(8000);
            log.Info("等待8秒");
        }
    }

转载于:https://www.cnblogs.com/sunguojiang/archive/2012/08/21/2648969.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值