I am used to the old WCF way of timers/ticking. I want, for example, a certain method to be called every 25th second. How do I do this in .NET Core?
Asked
Active
Viewed 1,636 times
2
-
What do you mean by `tick`? Do something every `x` seconds? – Cullub Apr 12 '17 at 19:16
1 Answers
1
You can use a System.Threading.Timer. Be aware that this Timer is not thread safe - see this question for details: Timer (System.Threading) thread safety .
namespace TimerApp
{
public class Program
{
public static void Main(string[] args)
{
using (new System.Threading.Timer(DoSomething, null , 0, 250))
{
// do something else
Thread.Sleep(TimeSpan.FromDays(1));
}
}
public static void DoSomething(object state)
{
// called every 250ms
Console.WriteLine(DateTime.Now);
}
}
}

Community
- 1
- 1

Dávid Molnár
- 10,673
- 7
- 30
- 55