.NET, event every minute (on the minute). Is a timer the best option?

后端 未结 14 2260
-上瘾入骨i
-上瘾入骨i 2020-11-27 03:02

I want to do stuff every minute on the minute (by the clock) in a windows forms app using c#. I\'m just wondering whats the best way to go about it ?

I could use a t

14条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 03:46

    What about a combination of aquinas' answer and 'polling': (apologies for the mixture of languages)

    def waitForNearlyAMinute:
        secsNow = DateTime.Now.Second;
        waitFor = 55 - secsNow;
        setupTimer(waitFor, pollForMinuteEdge)
    
    def pollForMinuteEdge:
        if (DateTime.Now.Second == 0):
            print "Hello, World!";
            waitForNearlyAMinute();
        else:
            setupTimer(0.5, pollForMinuteEdge)
    

提交回复
热议问题