0

I have got an ASP.NET MVC 4 application, and I want it to send a report e-mail every week. I've read about Quartz.NET, but it's too powerful for this easy task. Now I'm trying to use NCron, but it requires an initialiser in the Main() method (with obligatory parameter args):

class Program
{
    static void Main(string[] args)
    {
        Bootstrap.Init(args, ServiceSetup);
    }
}

Is there the way to do this in the Application_Start()? What should I pass as a args param? What other solutions can solve this task?

Jørn Schou-Rode
  • 37,718
  • 15
  • 88
  • 122
Egor Shoba
  • 95
  • 1
  • 8
  • _"I want it to send report e-mail every week"_ - create a [Scheduled Task](http://windows.microsoft.com/en-US/windows7/schedule-a-task). – CodeCaster Nov 22 '13 at 11:20

2 Answers2

0

You'll have to look up what ncrone does with those parameters. What this does is pass the command-line arguments of your windows app to the component. If you're using it on a web app, you don't have command-line args so if it needs arguments, you will have to construct the arguments yourself (either hard-coded or from a config-file or a database or ...)

It's also possible that these are optional, then you can just pass in an empty array (but again, check the docs of ncrone)

Also, keep in mind that when your application shuts down (standard that is after 20 minutes without any activity), your cron runner will not wake it up. If that will be the case you either need to keep the application alive by assuring that at least one request is done every 20 minutes or configure IIS to keep it alive always.

Kenneth
  • 28,294
  • 6
  • 61
  • 84
0

Author of NCron speaking…

First: I have never myself integrated NCron into a web application, and I am not sure how well it will work. For instance, as Kenneth points out, IIS will shut down your app if it does not receive any traffic, and there might be other hiccups as well.

In order to integrate NCron into a web app, I suggest that you ignore Bootstrap.Init() (designed specifically as an entry point to console apps) and rather work directly with SchedulingService:

using (var service = new SchedulingService())
{
    service.Hourly().Run<DataUpdateJob>();
    service.Daily().Run<RecycleCacheJob>();

    service.Start();
}

Again: I have never done this myself, but please do give it a try, and let me and everyone else know how you fare.

Jørn Schou-Rode
  • 37,718
  • 15
  • 88
  • 122
  • Using this code I'm getting message that there's no constructor for this type... Wherever I try to call it. Am I doing something wrong? (usings are correctly added) – Egor Shoba Nov 25 '13 at 06:00
  • No constructor for `SchedulingService`? I have not tried this myself, but the code certainly shows a public constructor: https://github.com/schourode/ncron/blob/master/src/NCron/Service/SchedulingService.cs#L43 – Jørn Schou-Rode Nov 28 '13 at 09:17