I have a .NET 5.0 Console project.
On start of my program it starts a timer:
public class ApiBase : IHostedService
{
public static System.Threading.Timer mailScanTimer;
private void OnStarted()
{
Console.WriteLine("Started...");
Logger.Log("Started...");
mailScanTimer = new System.Threading.Timer(
MailScanTask.MailScanTimerLine, null, 5, Timeout.Infinite);
}
}
And this is the function the timer calls:
public async static void MailScanTimerLine(object state)
{
await Task.Run(GetTicketEmailData);
await Task.Run(GetMailData);
Thread.Sleep(5000);
ApiBase.mailScanTimer.Change(0, Timeout.Infinite);
}
The program runs on a Linux server and after 2 to 3 weeks it suddenly stop work.
Is there something wrong with the code? Does someone have any tips to make it better?
Thanks in advance!