class Program
{ public static ILog log = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private static System.Timers.Timer aTimer = new System.Timers.Timer(); private static DateTime dt = DateTime.Now;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 = 1440 * 60 * 1000; ThreadPool.SetMaxThreads(30, 30); DateTime time = DateTime.Now;int runTime =Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["runTime"]);
if(time.Day==runTime) { // ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), time); DoWork(time.AddMonths(+1)); dt = DateTime.Now; } log.Info("TimerRrun-TimeEnd:" + DateTime.Now); } public void DoWork(object date) { try { CustomerConfig customerRegistry = new CustomerConfig(); int ret = 0; customerRegistry.Timeout = 1800000; ret = customerRegistry.CustomerDataTableByTime(Convert.ToDateTime(date), Convert.ToDateTime(date).AddMonths(+1), "");//为所有数据库创建分表 log.Info(date+"月份的分表完成,执行返回值ret="+ret); } catch (Exception e) { log.Info("客户分表过程出现异常:", e); } } }