我正在制作一个每隔1,5或30分钟甚至每小时通知用户的应用程序.例如,用户在5:06打开程序,程序将在6:06通知用户.
所以我当前的代码使用Thread.Sleep()函数每隔5分钟通知用户,但我发现它有点蹩脚.
这是我的代码:
public void timeIdentifier()
{
seiyu.SelectVoiceByHints(VoiceGender.Female);
while(true)
{
string alarm = String.Format("Time check");
seiyu.Speak(alarm);
string sayTime = String.Format(DateTime.Now.ToString("h:mm tt"));
seiyu.Speak(sayTime);
// It will sleep for 5 minutes LOL
Thread.Sleep(300000);
}
}
Run Code Online (Sandbox Code Playgroud)