How to call a method after so many seconds?

后端 未结 5 886
太阳男子
太阳男子 2020-12-06 22:31

In my project I would like to be able to call a method after 3 minutes have passed. There is no \"main loop\" to speak of so I cannot use a stopwatch and constantly check if

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 23:20

    Use a Timer.

    While there will be a slight overhead if you create a 1000 timers, it won't be too much. Timers will do their job and fire an event when 3 minutes have passed. Also, if you want your code to repeat every 3 minutes, Timers are the way to go.

提交回复
热议问题