问题
I have a WCF solution that runs under IIS. Some of the data I need to give back to clients comes from a third party website that we will need to poll frequently to get any new data.
Would it be a bad practice to create a Timer in the Application_Start() method to run a recurring background Task for this purpose? And if it's not a good idea, then what do you recommend?
回答1:
No it's not a good idea. The reason for this is that IIS can and will unload your app domain for many different reasons. When this happens there's no warning, and the app domain may stay unloaded for a long time, even until a request comes in to "wake it up".
To achieve what you want you should offline this polling process and make it durable across IIS appdomain unload/load cycles. There are a few different techniques for this, but I would recommend hangfire.
来源:https://stackoverflow.com/questions/29354953/good-way-to-run-recurring-background-task-in-wcf