Winforms Timer for Dummies

前端 未结 4 1932
面向向阳花
面向向阳花 2020-12-03 03:09

I\'m trying to get a timer to tick once a second in a winform, when I look for advice on how to do this I find loads of stuff about threads. Well I don\'t care about threads

4条回答
  •  既然无缘
    2020-12-03 04:00

    Apart from taking out the loop (as per jasonh's answer), your approach could become a little inaccurate if the app is kind of busy. Although you specify their interval in milliseconds, WinForms timers have a 18 ms resolution and have a very low priority, the message loop only checks timers if it finds nothing else to do.

    So, keep a StartTime (DateTime) value and use that to calculate the remaining time in every Timer event. You just could need 61 tick to reach a minute.

提交回复
热议问题