Need job scheduler in asp.net

霸气de小男生 提交于 2019-11-29 01:10:59

问题


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?


回答1:


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.




回答2:


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)




回答3:


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.




回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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/




回答8:


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.




回答9:


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!



来源:https://stackoverflow.com/questions/781300/need-job-scheduler-in-asp-net

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