开发者

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

开发者 https://www.devze.com 2023-03-03 12:16 出处:网络
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\

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号