问题
使用BackgroundService或者IHostedService做后台定时任务的时候部署到iis会出现不定时定时任务取消的问题,原因是iis会定时的关闭网站
解决
应用程序池修改为AlwaysRunning
修改web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration><location path="." inheritInChildApplications="false"><system.webServer><handlers><add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /></handlers><aspNetCore processPath="dotnet" arguments=".\xxxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"><handlerSettings><handlerSetting name="experimentalEnableShadowCopy" value="true" /><handlerSetting name="shadowCopyDirectory" value="./ShadowCopyDirectory/" /></handlerSettings></aspNetCore></system.webServer></location><!--新增代码在这--><system.webServer><applicationInitialization doAppInitAfterRestart="true"><add initializationPage="/notify/start" hostName="http://127.0.0.1:5000" /></applicationInitialization></system.webServer>
</configuration>
参考
https://blog.csdn.net/maaici/article/details/108620830