'Task.Delay() doesn't work with big TimeSpan (an hour), but works with smaller (10 minutes)
My code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using Telegram.Bot;
namespace ClassLibrary
{
public class TimerClass
{
public static async Task StartTimer(Quiz quiz)
{
while (StudyDay.GetNearestLesson().TotalMilliseconds > 0)
{
Console.WriteLine("Time from TimerClass: " +
StudyDay.GetNearestLesson().TotalMilliseconds);
await Task.Delay(StudyDay.GetNearestLesson());
quiz.Show(quiz);
}
Console.WriteLine("END");
}
}
}
StudyDay.GetNearestLesson().TotalMilliseconds
gives a correct result.
If time is a minute or 10 minutes, my program works, but if it's an hour, my programs doesn't work. May the reason be that my Mac goes into sleep mode, while this app is running? Please show me how to change my program^-^
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|