计时器的内部秒表在C#中不工作

问题描述 投票:1回答:1

我有这样的代码:

if (!App.stopWatch.IsRunning) { App.stopWatch.Start(); }
Device.StartTimer(new TimeSpan(0, 0, 1), () =>
{
   if (App.stopWatch.IsRunning && App.stopWatch.Elapsed.Seconds >= 60)
   {
      Console.WriteLine("Reducing Points");
      App.stopWatch.Restart();
   }
   return true;
});

我预计,每隔60秒会进入,如果写一个消息到控制台。但是,当我在调试模式下运行时,它永远不会有,什么是更混乱让我看到秒表经过时间上升到60个,然后复位。有没有人有任何想法,为什么这可能发生?

c#
1个回答
5
投票

Seconds结构的TimeSpan属性获取的时间间隔的秒分量。该类型是int,该值的范围为-59到59如果你有59秒的TimeSpan和您添加一秒钟,它则Seconds属性将成为0.Minutes财产变成1

如果你想通过一个TimeSpan占总秒,那么你需要TotalSeconds(这是一个double,因为它也代表了已经过去的分数的秒数。

© www.soinside.com 2019 - 2024. All rights reserved.