I have this code in asp.net core: "using cryptotasky.Models; namespace cryptotasky {…
- User
I have this code in asp.net core: "using cryptotasky.Models;
namespace cryptotasky { public class DailyResetService : IHostedService, IDisposable { private Timer _timer;
codepublic System.Threading.Tasks.Task StartAsync(CancellationToken cancellationToken) { var now = DateTime.Now; var nextRunTime = DateTime.Today.AddDays(1).AddHours(0).AddMinutes(0).AddSeconds(0) - now; // Calculate the time until the next desired run _timer = new Timer(DoWork, null, nextRunTime, TimeSpan.FromDays(1)); // Run the DoWork method every 24 hours return System.Threading.Tasks.Task.CompletedTask; } private void DoWork(object state) { using (CryptoTContext db = new CryptoTContext()) { var all = db.Users.ToList(); foreach (var user in all) { user.DailyDoneTasks = 0; } db.SaveChanges(); } }" the Dowork() function runs every day at 12:00:00AM i want PerformActionWhenCloseDateReached() to run every hour.
- Assistant
To make the
PerformActionWhenCloseDateReached()method run every hour, you can modify the existing code and add another timer that executes the method at the desired interval. Here's an updated version of your code: