how to schedule a task in MVC4 C#?

前端 未结 7 1376
借酒劲吻你
借酒劲吻你 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:24

    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

提交回复
热议问题