views:

1820

answers:

10

Hello Team,

We have a website where we need a scheduler to receive notifications (e-mail) on specific time. eg. a person setting reminder at 5 PM to attend the meeting at 4:45 PM, will receive email at 4:45 PM about same.

As this site is hosted on shared server, we don't have any control over the server to run any SQL Job or scheduler application.

Is there anything in asp.net which can help in this scenario?

+2  A: 

With ASP.NET you are not guaranteed that your app is alive at all times, and thus web applications as a host process for a scheduling solution is not feasible IMO.

A Windows service is what you need for this scenario. You have full control on starting and stopping the process as well as ways of monitoring the application.

Are you able to host such a service on a different machine? Even if the web application is running on a hosted server doesn't mean you have to run the scheduler on the same server.

Peter Lillevold
In addition, the windows service can simply call a web service on your hosted site to kick off the task, simplifying things further.
Robert Paulson
+1  A: 

If you really have no control over the server (meaning, you cannot use an sql job, a scheduled task, or install a windows server) then you could use a System.Threading.Timer that you initialize in your Global.asax (e.g, on application startup) that invokes a certain method in your application every x minutes. This method would then query your database and see what notifications need to be send.

This is really not a desirable approach though, as the timer is not guaranteed to always invoke as far as I know, since, like Peter says, your web application is not guaranteed to be alive at all times.

However, depending on your requirements, it can still be a 'good enough' approach if you have no other options.

Razzie
+1  A: 

However if you really are completely stuck and have no choice but to host it in your WebApp,

You could look at creating a System.Timers.Timer instance in your Global.asax.cs file. Wire up a Elapsed event as you normally would, and give it some code that does something along the lines of

protected void myTimer_Elapsed(object sender, EventArgs e)
{
    if(System.DateTime.Now Falls in Some Configured Time-Window)
        //Do Stuff
}

But as someone pointed out, its not guaranteed as IIS might be resetting during that period, in which case you'll miss it.

Eoin Campbell
+8  A: 

How about this: Simulate a Windows Service using ASP.NET to run scheduled jobs.

At one point this technique was used on Stack Overflow, although I don't think it is any more.

To be honest it seems like a nasty, error-prone hack to me, but if you're unable to run anything on the server except your website then something like this is probably your only option.

LukeH
100% agree with the analysis of that method. However, as long as you understand the limitations going in (IE: that a "scheduled" job may not run exactly when it's scheduled for) then it may be a good solution.
Chris Lively
A: 

It's really not desirable to do, but you can do what Razzie is suggesting. I have seen it done many times. Although ugly, sometimes ya just have to do the ugly hacks.

Using this method though, you have to make sure you application is not unloaded. So you need some sort of keep alive. I would suggest setting up a web monitoring tool that will constantly pull a page (aspx) to keep the application alive. These guys are free http://mon.itor.us/

Chad Grant
I think it would be better to do what @Arjan Einbu suggests. Something like http://mon.itor.us looks like a very simple way to set up the necessary external page requests.
codeape
Then you have a dependency on your app that the other machine has to be running and you have to remember it ;) I would forget or the machine would reboot due to updates etc.. any way you do it ... these are all ugly hacks ;)
Chad Grant
+4  A: 

You need to have a job done at the server, but you have no good way of triggering it from ASP.NET?

How about creating a webpage that will start your job, and have a timer run elsewhere (ie. on another computer) that requests that page. (Just hitting the page to trigger you jobs)

Arjan Einbu
+1 IMO, this is the simplest, most reliable way to accomplish this.
codeape
Simple, yes. But reliable??
Joel Mueller
@joel mueller: Yes, why not?
Arjan Einbu
Well, if you can have a timer going, why not have the timer just run your code, instead of having something running on a different machine requesting a web page? You're adding network communication and a second machine to your workflow, which means additional potential points of failure. Which means less reliable.
Joel Mueller
@joel mull. Point taken. But for the "why not have the timer just run in your code" see first part of Peter Lillevolds answer...
Arjan Einbu
The first part of Peter Lillevold's answer is why you shouldn't embed code that has nothing to do with displaying a web page into ASP.NET. I agree with his suggestion of a Windows Service - I use Quartz.NET in mine, as Bård suggests.
Joel Mueller
Guys, don't forget that ASP.Net also means web services. There's nothing wrong with having a timer running somewhere that calls a web service in the ASP.Net app.
Peter Lillevold
+3  A: 

I had the same problem as you and I ended up with a programming a service that utilize Quartz.NET: http://quartznet.sourceforge.net/ and connect to the same database as the website.

Bård
A: 

I don't belive you, because source code of Quartz.Net (1.0 and 1.0.1) doesn't compile under Visual Studio.Net 2005 and 2008. The only way to get Quartz.Net is to use whole Spring.Net package, which compiles fine under VS.Net 2005 and 2008

Unless you could share some tips, how to compile and use quartz.dll in asp.net project! (web page of Quartz.Net and readme.txt doesn't provide any information on source coude compilation) Every tip is welcomed!

A: 

I don't belive you, because source code of Quartz.Net (1.0 and 1.0.1) doesn't compile under Visual Studio.Net 2005 and 2008. The only way to get Quartz.Net is to use whole Spring.Net package, which compiles fine under VS.Net 2005 and 2008

Unless you could share some tips, how to compile and use quartz.dll in asp.net project! (web page of Quartz.Net and readme.txt doesn't provide any information on source coude compilation) Every tip is welcomed!

I had trouble at first as well, but this is because the necessary AsemblyInfo.cs is contained in the parent folder. Also, you'll need to add the three DLLs that are included.

NovaJoe
A: 

Could anyone give exact instructions on how to load Quartz.Net on a server? Thanks

Michael Lasell