Timer check without interupth the program gets slow or stuck

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Hello,

we like to get a timer that checks when the system date change
so we suppose to check it every hour or a complete day...
then to refresh our form

but no idea how to do it and even without to make the program slow or cpu overloading

Thanks.
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Here's a snippet that is meant to run every hour, exactly on the hour:
Code: Select all
    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Dim aTimer As New System.Timers.Timer(MillisecondsToNextTopOfTheHour)
        AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
        aTimer.Start()
    End Sub

    Private Shared Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs)
        Dim aTimer As System.Timers.Timer = CType(source, System.Timers.Timer)
        aTimer.Stop()

        'Enter code here to change your calendar or whatever you need to happen each hour

        aTimer.Interval = MillisecondsToNextTopOfTheHour()
        aTimer.Start()
    End Sub

    Private Shared Function MillisecondsToNextTopOfTheHour() As Double
        Return DateTime.Today.Add(New TimeSpan(DateTime.Now.Hour, 0, 0)).AddHours(1).Subtract(DateTime.Now).TotalMilliseconds
    End Function
Should be easy to incorporate in to your code.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

Okay Thanks Codenstuff

lets see what i can do with it ;)


Edit:

Just wonderful and no much cpu at all either
thanks ;)

Dummy
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
3 posts Page 1 of 1
Return to “Tutorial Requests”