i have this method:
public void GiveMoney()
foreach (Team t in teamRepository.FindAll())
I use this line to call the method every minute:
RecurringJob.AddOrUpdate(() => GiveMoney(), Cron.Minutely);
The method isn’t being called…
This works perfectly however:
RecurringJob.AddOrUpdate(() => Debug.WriteLine("hello"), Cron.Minutely);
So the foreach loop isnt being executed, why?
Are any errors being raised ? Where does teamRepository come from, what is its life-cycle and is it thread safe ?
Is that verbatim code? Off the top of my head, GiveMoney() not instantiated anywhere in a class or even a static.
Not entirely sure here but I would guess that
Debug.WriteLine is a static method, but
GiveMoney is actually an instance method and in your recurring job the object can’t be instantiated…
THe problem was that I didn’t have a default constructor for my controlle, which delivered some other errors. It all came down to this => i needed to make adjustments to my ninjectwebcommon.cs, more particular, I added this line to registerservices:
please keep in mind that I am speaking without full context, but spawning an ASP.NET controller object to perform a simple DB operation, seems like could be better factored as a static function that both call.