问题描述:
C#代码中定义运用了 timer 定时器,是挂在IIS服务上的,定时器运行20分钟后自动结束了
问题原因:
IIS-应用程序池-高级设置-进程模型-闲置超时(分钟):20
因为IIS的垃圾回收机制,会对 timer 进行计时回收,所以超过20分钟后,就被IIS自动回收了
解决方法:
1:简单除暴,将闲置超时时间改为1440分钟,即24小时
2:使用using
using (tcpHeartTimer = new System.Timers.Timer(5000))
{
tcpHeartTimer.Enabled = true;
tcpHeartTimer.Elapsed += new ElapsedEventHandler(CheckCameraTcp);
tcpHeartTimer.AutoReset = true;
tcpHeartTimer.Start();
LogHelper<StoDSTcpServer>.Debug($"CameraTcp客户端心跳包保活开启完毕!");
}