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://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)