Hi,
I'm writing a program that needs to run a sub once on the hour every hour.
is there w way to do this without using a timer control?
as this takes up too much reasources when running 24/7
Thanks
Printable View
Hi,
I'm writing a program that needs to run a sub once on the hour every hour.
is there w way to do this without using a timer control?
as this takes up too much reasources when running 24/7
Thanks
You have to use some sort of timing object. Here is the way I would do it if I didnt' want to use a "visual control"
Code:
Private MyTimer As System.Timers.Timer
Private Sub MyTimerSub(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
'Code every hour goes here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MyTimer = New System.Timers.Timer(3600000)
AddHandler MyTimer.Elapsed, AddressOf Me.MyTimerSub
MyTimer.Start()
End Sub
that is exactly what I >>am<< using.
The problem is that the timer is going tick tick tick tick.... tick tick tick... and every time that timer ticks it uses a percentage of memory after a few days of running the computers it is running on has slowed down, due to the timer using all the resources.
I wanted to know if there was a way to run the sub using the system clock? so when it was exactly an hour from last run it will run again.
I think that no matter what you do, you'll have some process running at all times checking on the time to see what time it is.
Your best bet would be to setup the scheduler that comes with WinXP to schedule the app to run every hour. They windows is doing all the processing and your app will only run every hour.
No matter where it is done, a timer has to be involved.
Hi,
You say that after a few days of running the timer has consumed too much of your resources. In the beginning of the sub you wish to run, set Timer.Enabled to false and then set it to true just before the sub is vacated when you will obviously have to synchronise the timer with the actual time.
right ok thanks,
well never mind :D
I have just added a log to the program, and I have just realised that the program runs every 10mins lol, in stead of every hour... oops... maybe changing that will help to.
Thanks again,