kona
kona

Reputation: 139

Scheduling in ASP.NET

Basically I need a simple, yet scalable scheduling solution to be used in a shared hosting environment (until dedicated hosting can be afforded) to send push notification requests to Apple (just fire and forget). It only needs to fire while there are active sessions, but should pick up again when a page is fired up again. I need it to fire roughly every two minutes. But accuracy isn't that important, just as long as it fires.

Like this article (Scheduled Tasks in ASP.NET), I've come across several sites (and stackoverflow answers) that propose the use of timers, cache expiration techniques, or threads, for scheduling. But timers AND cache expirations aren't firing for me in global.asax, and threading just causes the visual studio JIT debugger to be thrown up, but I'm unable to catch any exceptions in any of the code (the project was created as an http website in visual studio, not a web project - so no stepping through the debugger - just try catch - yay).

I've even tried Quartz.net, but can't get it to fire even once, plus it's overkill given my simple needs.

Anyone successfully gotten scheduling to work in .Net in any capacity?

Upvotes: 0

Views: 428

Answers (2)

Wyatt Barnett
Wyatt Barnett

Reputation: 15663

Using scheduled tasks in ASP.NET is generally not a workable idea, even with dedicated hosting. Two realistic ways to solve this problem:

a) Upgrade to a VPS. More expensive than shared but still affordable -- I've got a small one for $300/year. Then you can solve this in a pretty rational manner -- write your own command line utility and use the task scheduler.

b) Distribute your application a bit. You can design this one of two general ways. The first would be to setup a command and control web service in your app. Then you could build a small command line utility to ping the service and tell it to push the push notifications. Then you just need an internet connected pc to fire the commands off. Like your home desktop. You could also flip this around and setup your app to expose data over another web service and have the brains of the push notification running offline on your home PC. This is quite a bit more complex, in most cases I would go with the former option.

Upvotes: 1

Steve Wellens
Steve Wellens

Reputation: 20640

Asp.net is designed to respond to client requests.

It is not for making an active program that sits in the background, wakes up on it's own and does stuff. Although you CAN make it do that (as you have found) the solutions are hacks.

You'll have to implement one of the hacks or rethink your goals.

Here are a few more of the hacks:

http://www.codeproject.com/KB/aspnet/ASPNETService.aspx

http://www.west-wind.com/weblog/posts/2007/May/10/Forcing-an-ASPNET-Application-to-stay-alive

http://www.mikesdotnetting.com/Article/129/Simple-task-Scheduling-using-Global.asax

Upvotes: 2

Related Questions