I have a .NET console app and every 5mins when my code is blocking (console.readline()) i’d like to run a task on the side. I also have other threads which may need to run a task in X mins later if they are blocking. Is there something like SetInterval(timespan, func) in .NET?
I have a .NET console app and every 5mins when my code is blocking
Share
Sure there is. System.Timers.Timer, or System.Threading.Timer, depending on your needs. See this page for a comparison of the various timers.
As Steve mentions in the comments, the only one that is clearly inappropriate is System.Windows.Forms.Timer (because it requires a message pump, which you don’t (usually) have in a console app).