Can you run a “service” that runs a scheduled task from an ASP.Net project?

孤街醉人 提交于 2019-12-07 05:38:42

问题


I built a Windows Service for a client of ours that collects all the changed/new rows from the database, turns them into a CSV and FTP uploads them somewhere every night. Now as it turns out they don't have access to install or run a Windows Service (it's a web path only hosted solution).

I thought it would be easy enough to modify the Windows Service code to run inside the ASP.Net process and instantiated from the Global.asax (I've done this in the past, hosting a WCF service from within a MVC project). We're on ASP.Net 4.0, using web forms, and this task runs Quartz and OpenPG every night at midnight (or another configured time).

My boss was concerned about the hosting process sleeping or unloading during prolonged periods of no one hitting the site. I'm pretty sure this doesn't happen but I don't know with absolute certainty.

Will this work as I'm thinking it will, or will there be some issue to implementing it this way?

Thanks!

Edit: I know you "can" (create an object and call a method that doesn't block the execution of Application_Start that fires a timer or background thread or something and runs code in the background) but is it a good idea and will the ASP.Net hosting process sleep/kill the thread it's running on? If so, can I spawn a new thread (either create my own thread, or consume one from the pool) and have it run infinitely without being killed?


回答1:


By default IIS will shutdown an idle process. You can change this though, but you still face the risk that a web process can't be guaranteed to be running. The worker process setting should go some way to keeping it running.




回答2:


Use Window's Task Scheduler....this is a perfect example of what it's for. You can have it call your assembly directly or you can just use it to call a WCF endpoint in your website.



来源:https://stackoverflow.com/questions/5904115/can-you-run-a-service-that-runs-a-scheduled-task-from-an-asp-net-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!