21

I wanna create a notification system on my website?(something like stack-overflow)
How can we schedule a task for mailing the notification for users on each 24 hours?

Can we use MVC4 or we should use windows service ?

Edit:
My Experience with using FluentScheduler in 3 month within a MVC4 App .
FluentScheduler is easy to config and using but it doesn't run tasks any time. Sometimes run and sometimes doesn't run.
I think the best way for scheduling is Windows Service to ensure running a task at the specific time.

Mohammad Dayyan
  • 21,578
  • 41
  • 164
  • 232

7 Answers7

16

Found this to be an awesome scheduler, FluentScheduler

Usage:

// Schedule an ITask to run at an interval
    Schedule<MyTask>().ToRunNow().AndEvery(2).Seconds();
heads5150
  • 7,263
  • 3
  • 26
  • 34
  • That dll looks awesome. I'm going to do a deep look at it. – Jordi Jan 31 '13 at 07:29
  • I'm referring to the syntax, not the functionality. What's wrong with `Schedule(runNow: true, runEvery: TimeSpan.FromSeconds(2));`? Furthermore, if you look at the implementation, because of the terrible fluent syntax, it's full of race conditions and possible unintentional side effects. – Mark Jul 16 '13 at 14:41
  • 2
    @Mark Thanks for the clarification. I have to disagree I think (implmentation aside) it's one of the better fluent syntax's. For the most part it is 'human' readable. 'Schedule a task to run now and every 2 seconds'. There's nothing wrong with your suggestion but I think a well thought out fluent syntax can be very helpful. – heads5150 Jul 16 '13 at 22:16
  • Is a fluent syntax helpful if it makes it impossible to correctly and safely start a timer? "It doesn't always work, but at least the code looks pretty..." That'd get you fired (and people dead, when you do what I do) around here. – Mark Jul 18 '13 at 18:27
  • Could anyone share any MyTask implementation, how should I define a custom task class? – Felix Aballi Jan 10 '14 at 21:31
  • I'm using it for around 6 months, but it doesn't run the task every time, do you know another reliable one – Mohammad Dayyan Apr 08 '14 at 05:47
  • 1
    @Mohammad If it's not suitable for your situation. Look at building a windows service. – heads5150 Apr 08 '14 at 11:18
  • @heads5150 you're right, `FluentScheduler` doesn't work any time, I think the best way is `Windows Service` – Mohammad Dayyan May 26 '14 at 07:50
7

You need a .Net Job Scheduler. Here is a good one: http://quartznet.sourceforge.net/

phnkha
  • 7,782
  • 2
  • 24
  • 31
3

You can use ATrigger scheduling service. A .Net library is also available to create scheduled tasks without overhead. Errors log, Analytics, Tasks Listings and more benefits.

Disclaimer: I was among the ATrigger team. It's a freeware and I have not any commercial purpose.

2

maybe you wanna use a scheduled task. Doing this in a MVC is a bad idea (mixing responsabilities) and building a windows service looks like an overkill to me (because is something doesn't need to run all the time).

Jordi
  • 2,789
  • 1
  • 20
  • 35
1

I use scheduled task of windows.

I have build a little app than enter a record in the bd, then access the website with this recordId(Guid) as a parameter.

In mvc i check if the id exist, if it exist i run tasks then delete the record in the db, if not i ignore it.

this way im able to add schedule with a param. without updating the app each time i need a new scheduled task. i just add a new task like "myapp.exe /MyNewTaskName"

hope this help someone ;-)

Benoit
  • 1,109
  • 14
  • 29
1

First of all;

  1. Add Nuget package Install-Package FluentScheduler
  2. Add your registry class that inherit Registry and some code
// Schedule a simple task to run at a specific time
Schedule(() => System.Diagnostics.Debug.Write("This is from service " + DateTime.Now.Second+"\n"))
               .ToRunNow().AndEvery(2).Seconds();
  1. Register that registry class in Application_Start of Global.asax.cs with TaskManager
TaskManager.Initialize(new Test());

GitHub

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76
Baqer Naqvi
  • 6,011
  • 3
  • 50
  • 68
0

There is also a built-in option, QueueBackgroundWorkItem. It was added in .Net 4.5.2 and here is a guide on how to use it in MVC.

In addition to previously mentioned FluentScheduler you also have HangFire. And if you plan on deploying to Azure there's a handful of different services for this.

Andreas Bergström
  • 13,891
  • 5
  • 59
  • 53