writing a service to periodically retrieve XML and

2019-09-03 14:34发布

问题:

I'm a .Net guy, and I'm interested in starting this project but I'm not sure what the best approach is.

I want to do the equivalent of writing a windows service, that periodically hits a site to get XML, (say google weather) and then sends SMS messages if certain criteria are met (ie it's going to freeze tonight, and it did not freeze last night(so I know to cover up my faucets, etc)).

So my question is two fold, is there some hosted app out there that does this already?

If not what's the best approach? I could just whip it up in c# and run it on my local box, but then it'd have to alway be on and connected.

Are there Hosting services that let you run a .Net service instead of a web server?

Is there some obvious better way to do this that I'm missing?

I feel like there should be a really simple solution and I'm staring right at it...

回答1:

It doesn't necessarily have to be a service. You could have an Asp.Net website that runs a separate thread in the background that does what you're looking to do. You could set up the thread in the application start event and then never terminate the thread. The caveat here is how IIS recycles the app pool - it might not restart the pool until a web page is requested.