how to schedule a task in MVC4 C#?

前端 未结 7 1351
借酒劲吻你
借酒劲吻你 2020-12-09 16:22

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?

相关标签:
7条回答
  • 2020-12-09 17:04

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

    0 讨论(0)
  • 2020-12-09 17:07

    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.

    0 讨论(0)
  • 2020-12-09 17:16

    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).

    0 讨论(0)
  • 2020-12-09 17:21

    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 ;-)

    0 讨论(0)
  • 2020-12-09 17:22

    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.

    0 讨论(0)
  • 2020-12-09 17:23

    Found this to be an awesome scheduler, FluentScheduler

    Usage:

    // Schedule an ITask to run at an interval
        Schedule<MyTask>().ToRunNow().AndEvery(2).Seconds();
    
    0 讨论(0)
提交回复
热议问题