How to use the .NET Timer class to trigger an event at a specific time?

前端 未结 9 1692

I would like to have an event triggered in my app which runs continuously during the day at a certain time, say at 4:00pm. I thought about running the timer every second and

9条回答
  •  日久生厌
    2020-12-01 00:43

    Echo to Dan's solution, using Timercallback is a quick and neat solution. Inside the method you want to schedule a task or subroutine to be run, use the following:

        t = New Timer(Sub()
                            'method call or code here'
                      End Sub, Nothing, 400, Timeout.Infinite)
    

    use of 'Timeout.Infinite' will ensure the callback will be executed only once after 400ms. I am using VB.Net.

提交回复
热议问题