This is a follow-up on my previous thread concerning having the program
wait for a certain date and time and then executing some code when it
gets there. My question is; can I use the Sleep function from kernel32
to accomplish this? My concern is that this function takes milliseconds
where my program needs to be accurate to within 5 minuets, and delays
may be as long as a number of days, months or whatever. Would I run into
many problems doing it this way? I was thinking that if an overflow
occurs then I could just take the maximum value that Sleep would accept
and then once that is done having a function check if the time really
did come or if a further delay is needed. Please let me know what you
think of this or if there is a better way to do this.
One more thing, how would I be able to implement this so that the delay
of execution of tasks is completely separate from the rest of the
program? That is, the user should still be able to access all the forms,
change settings, and do all of that. I almost have a desire to write
something like a service, but don't have a clue of where to even start
on that. 18 3163
"Max" <ma*****@yahoo.com> schrieb This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems doing it this way? I was thinking that if an overflow occurs then I could just take the maximum value that Sleep would accept and then once that is done having a function check if the time really did come or if a further delay is needed. Please let me know what you think of this or if there is a better way to do this.
Why not use a Timer and handle it's Elapsed event?
One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate
thread.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Max" <ma*****@yahoo.com> schrieb This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems doing it this way? I was thinking that if an overflow occurs then I could just take the maximum value that Sleep would accept and then once that is done having a function check if the time really did come or if a further delay is needed. Please let me know what you think of this or if there is a better way to do this.
Why not use a Timer and handle it's Elapsed event?
One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate
thread.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Armin Zingler wrote: "Max" <ma*****@yahoo.com> schrieb
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems doing it this way? I was thinking that if an overflow occurs then I could just take the maximum value that Sleep would accept and then once that is done having a function check if the time really did come or if a further delay is needed. Please let me know what you think of this or if there is a better way to do this.
Why not use a Timer and handle it's Elapsed event? One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate thread.
How much CPU power will it take if I have the timer running for a number
of days? That's really my only concern, if it doesn't take almost any
resources and is accurate enough then I think that solves my problem.
Armin Zingler wrote: "Max" <ma*****@yahoo.com> schrieb
This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems doing it this way? I was thinking that if an overflow occurs then I could just take the maximum value that Sleep would accept and then once that is done having a function check if the time really did come or if a further delay is needed. Please let me know what you think of this or if there is a better way to do this.
Why not use a Timer and handle it's Elapsed event? One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate thread.
How much CPU power will it take if I have the timer running for a number
of days? That's really my only concern, if it doesn't take almost any
resources and is accurate enough then I think that solves my problem.
"Max" <ma*****@yahoo.com> schrieb Why not use a Timer and handle it's Elapsed event? One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate thread.
How much CPU power will it take if I have the timer running for a number of days?
~ 0%, unless you want it to fire each millisecond, but as you said, much
less is sufficient.
That's really my only concern, if it doesn't take almost any resources and is accurate enough then I think that solves my problem.
CPU usage mainly depends on what you're doing when the timer event fires.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Max" <ma*****@yahoo.com> schrieb Why not use a Timer and handle it's Elapsed event? One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate thread.
How much CPU power will it take if I have the timer running for a number of days?
~ 0%, unless you want it to fire each millisecond, but as you said, much
less is sufficient.
That's really my only concern, if it doesn't take almost any resources and is accurate enough then I think that solves my problem.
CPU usage mainly depends on what you're doing when the timer event fires.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Armin Zingler wrote: "Max" <ma*****@yahoo.com> schrieb
Why not use a Timer and handle it's Elapsed event?
One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate thread.
How much CPU power will it take if I have the timer running for a number of days?
~ 0%, unless you want it to fire each millisecond, but as you said, much less is sufficient. That's really my only concern, if it doesn't take almost any resources and is accurate enough then I think that solves my problem.
CPU usage mainly depends on what you're doing when the timer event fires.
Ok I'm getting a hang of this and it seems to be working fine. Now
here's another question, in my program the minimum time between events
is 5 minuets. What do you think is better, to have the timer fire every
5 minuets and check if an event needs to be executed, or instead,
counting the number of years, months, days, hours, and minuets until the
next event, converting it into milliseconds, and setting that as the
interval? How accurate is this thing anyway? Would it even be able to
keep time for days and months or would I just be better of firing the
event every 5 minuets, synchronizing it with the system time, and then
starting it back up again?
Armin Zingler wrote: "Max" <ma*****@yahoo.com> schrieb
Why not use a Timer and handle it's Elapsed event?
One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
If you use the System.Timers.Timer, the Elapsed event occurs in a separate thread.
How much CPU power will it take if I have the timer running for a number of days?
~ 0%, unless you want it to fire each millisecond, but as you said, much less is sufficient. That's really my only concern, if it doesn't take almost any resources and is accurate enough then I think that solves my problem.
CPU usage mainly depends on what you're doing when the timer event fires.
Ok I'm getting a hang of this and it seems to be working fine. Now
here's another question, in my program the minimum time between events
is 5 minuets. What do you think is better, to have the timer fire every
5 minuets and check if an event needs to be executed, or instead,
counting the number of years, months, days, hours, and minuets until the
next event, converting it into milliseconds, and setting that as the
interval? How accurate is this thing anyway? Would it even be able to
keep time for days and months or would I just be better of firing the
event every 5 minuets, synchronizing it with the system time, and then
starting it back up again?
Max,
In addition to the System.Timers.Timer you may want to consider using the
System.Threading.Timer class also
The Threading.Timer allows you to set a TimeSpan on when the first event
should occur. So if you need the event in 5 minutes you pass a TimeSpan of 5
minutes, if you need the first event in 3 days, you pass a TimeSpan of 3
days. If you need the first event in 1 day, 2 hour, 3 minutes and 44
seconds, then you pass a TimeSpan of 1 day, 2 hours, 3 minutes, and 44
seconds...
The Timers.Timer you would need to convert the above TimeSpan into a double
that represents the milliseconds (TimeSpan.TotalMilliseconds is good for
this).
Of course the Timers.Timer have an AutoReset feature if you need only a
single Elapsed event. The Threading.Timer has a similar ability...
Either way the following recent articles in MSDN Magazine explain the
difference between the three timer objects in .NET & when to use each. http://msdn.microsoft.com/msdnmag/is...T/default.aspx http://msdn.microsoft.com/msdnmag/is...3/default.aspx
Another thought is rather then rely on a Timer you may want to consider the
Task Scheduler under the Windows Control Panel.
Hope this helps
Jay
"Max" <ma*****@yahoo.com> wrote in message
news:kd********************@comcast.com... This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems doing it this way? I was thinking that if an overflow occurs then I could just take the maximum value that Sleep would accept and then once that is done having a function check if the time really did come or if a further delay is needed. Please let me know what you think of this or if there is a better way to do this.
One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
Max,
In addition to the System.Timers.Timer you may want to consider using the
System.Threading.Timer class also
The Threading.Timer allows you to set a TimeSpan on when the first event
should occur. So if you need the event in 5 minutes you pass a TimeSpan of 5
minutes, if you need the first event in 3 days, you pass a TimeSpan of 3
days. If you need the first event in 1 day, 2 hour, 3 minutes and 44
seconds, then you pass a TimeSpan of 1 day, 2 hours, 3 minutes, and 44
seconds...
The Timers.Timer you would need to convert the above TimeSpan into a double
that represents the milliseconds (TimeSpan.TotalMilliseconds is good for
this).
Of course the Timers.Timer have an AutoReset feature if you need only a
single Elapsed event. The Threading.Timer has a similar ability...
Either way the following recent articles in MSDN Magazine explain the
difference between the three timer objects in .NET & when to use each. http://msdn.microsoft.com/msdnmag/is...T/default.aspx http://msdn.microsoft.com/msdnmag/is...3/default.aspx
Another thought is rather then rely on a Timer you may want to consider the
Task Scheduler under the Windows Control Panel.
Hope this helps
Jay
"Max" <ma*****@yahoo.com> wrote in message
news:kd********************@comcast.com... This is a follow-up on my previous thread concerning having the program wait for a certain date and time and then executing some code when it gets there. My question is; can I use the Sleep function from kernel32 to accomplish this? My concern is that this function takes milliseconds where my program needs to be accurate to within 5 minuets, and delays may be as long as a number of days, months or whatever. Would I run into many problems doing it this way? I was thinking that if an overflow occurs then I could just take the maximum value that Sleep would accept and then once that is done having a function check if the time really did come or if a further delay is needed. Please let me know what you think of this or if there is a better way to do this.
One more thing, how would I be able to implement this so that the delay of execution of tasks is completely separate from the rest of the program? That is, the user should still be able to access all the forms, change settings, and do all of that. I almost have a desire to write something like a service, but don't have a clue of where to even start on that.
Max, What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the
I'm currently working on a Windows Service that I am using a Timers.Timer
that the default interval is 1 hour. When the Elapsed event is raised it
checks for any current, pass due & future work. If future work is less then
an hour away it shortens the interval so the next event occurs when the next
unit of work should occur. The Elapsed event will process any current & pass
due work...
I have not yet, but I will probably make the default 1 hour interval
configurable in the app.config file.
Hope this helps
Jay
"Max" <ma*****@yahoo.com> wrote in message
news:YI********************@comcast.com... Armin Zingler wrote:
<<snip>> Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
Max, What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the
I'm currently working on a Windows Service that I am using a Timers.Timer
that the default interval is 1 hour. When the Elapsed event is raised it
checks for any current, pass due & future work. If future work is less then
an hour away it shortens the interval so the next event occurs when the next
unit of work should occur. The Elapsed event will process any current & pass
due work...
I have not yet, but I will probably make the default 1 hour interval
configurable in the app.config file.
Hope this helps
Jay
"Max" <ma*****@yahoo.com> wrote in message
news:YI********************@comcast.com... Armin Zingler wrote:
<<snip>> Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
"Max" <ma*****@yahoo.com> schrieb Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
I don't know how exact it is exactly, but if you use the first approach
you're on the safe side.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
"Max" <ma*****@yahoo.com> schrieb Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
I don't know how exact it is exactly, but if you use the first approach
you're on the safe side.
--
Armin
How to quote and why: http://www.plig.net/nnq/nquote.html http://www.netmeister.org/news/learn2quote.html
Armin Zingler wrote: "Max" <ma*****@yahoo.com> schrieb
Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
I don't know how exact it is exactly, but if you use the first approach you're on the safe side.
All right guys, thanks for your help. Think I'll go with Jay’s method,
there's no need to sync every 5 mins so the timer will stop and sync
every hour unless an event needs to happen sooner. Below I've pasted the
code of a module that I came up with. So far it seems to work fine, but
I've only tested it up to an event in 5 minuets. All it does right now
is give you a msgbox with the current time so you can determine if it
happened when it should have. I am about to start the thing and see if
it is able to correctly give me a msgbox in 1 hour 5 minuets. If you
want to give it a try then simply call function "LoadTimer()" first and
then call "SetTimer()", just be sure to change the value of NextEvent.
Feel free to use it if you like:
Module mdlTime
Private timer As New Timers.Timer
Private time As Date
Private span As TimeSpan
Private Const NextEvent As String = "5/2/04 6:05:00 PM"
Public Sub LoadTimer()
'Call this function first in order to configure the timer
AddHandler timer.Elapsed, AddressOf TimerFired
timer.AutoReset = True
End Sub
Public Sub SetTimer()
Dim delay As Double
time = time.Parse(NextEvent)
span = time.Subtract(time.Now)
'See if next event occurs within the next hour,
'otherwise set the timer to wait till the next hour of the day
If span.Hours = 0 Then
delay = (span.Minutes * 60000) + (span.Seconds * 1000) + span.Milliseconds
Else
delay = 3600000 - time.Now.Minute * 60000 - time.Now.Second * 1000 -
time.Now.Millisecond
End If
timer.Interval = delay
timer.Start()
End Sub
Private Sub TimerFired(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
timer.Stop()
MsgBox(time.Now)
SetTimer()
End Sub
End Module
Armin Zingler wrote: "Max" <ma*****@yahoo.com> schrieb
Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
I don't know how exact it is exactly, but if you use the first approach you're on the safe side.
All right guys, thanks for your help. Think I'll go with Jay’s method,
there's no need to sync every 5 mins so the timer will stop and sync
every hour unless an event needs to happen sooner. Below I've pasted the
code of a module that I came up with. So far it seems to work fine, but
I've only tested it up to an event in 5 minuets. All it does right now
is give you a msgbox with the current time so you can determine if it
happened when it should have. I am about to start the thing and see if
it is able to correctly give me a msgbox in 1 hour 5 minuets. If you
want to give it a try then simply call function "LoadTimer()" first and
then call "SetTimer()", just be sure to change the value of NextEvent.
Feel free to use it if you like:
Module mdlTime
Private timer As New Timers.Timer
Private time As Date
Private span As TimeSpan
Private Const NextEvent As String = "5/2/04 6:05:00 PM"
Public Sub LoadTimer()
'Call this function first in order to configure the timer
AddHandler timer.Elapsed, AddressOf TimerFired
timer.AutoReset = True
End Sub
Public Sub SetTimer()
Dim delay As Double
time = time.Parse(NextEvent)
span = time.Subtract(time.Now)
'See if next event occurs within the next hour,
'otherwise set the timer to wait till the next hour of the day
If span.Hours = 0 Then
delay = (span.Minutes * 60000) + (span.Seconds * 1000) + span.Milliseconds
Else
delay = 3600000 - time.Now.Minute * 60000 - time.Now.Second * 1000 -
time.Now.Millisecond
End If
timer.Interval = delay
timer.Start()
End Sub
Private Sub TimerFired(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
timer.Stop()
MsgBox(time.Now)
SetTimer()
End Sub
End Module
Max,
You do realize that instead of: delay = (span.Minutes * 60000) + (span.Seconds * 1000) + span.Milliseconds
You can use:
delay = span.TotalMilliseconds
Which will also take into account any Hours & Days in the TimeSpan.
Hope this helps
Jay
"Max" <ma*****@yahoo.com> wrote in message
news:nI********************@comcast.com... Armin Zingler wrote:
"Max" <ma*****@yahoo.com> schrieb
Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
I don't know how exact it is exactly, but if you use the first approach you're on the safe side.
All right guys, thanks for your help. Think I'll go with Jay’s method, there's no need to sync every 5 mins so the timer will stop and sync every hour unless an event needs to happen sooner. Below I've pasted the code of a module that I came up with. So far it seems to work fine, but I've only tested it up to an event in 5 minuets. All it does right now is give you a msgbox with the current time so you can determine if it happened when it should have. I am about to start the thing and see if it is able to correctly give me a msgbox in 1 hour 5 minuets. If you want to give it a try then simply call function "LoadTimer()" first and then call "SetTimer()", just be sure to change the value of NextEvent. Feel free to use it if you like:
Module mdlTime Private timer As New Timers.Timer Private time As Date Private span As TimeSpan Private Const NextEvent As String = "5/2/04 6:05:00 PM"
Public Sub LoadTimer() 'Call this function first in order to configure the timer AddHandler timer.Elapsed, AddressOf TimerFired timer.AutoReset = True End Sub
Public Sub SetTimer() Dim delay As Double
time = time.Parse(NextEvent) span = time.Subtract(time.Now)
'See if next event occurs within the next hour, 'otherwise set the timer to wait till the next hour of the day If span.Hours = 0 Then delay = (span.Minutes * 60000) + (span.Seconds * 1000) + span.Milliseconds Else delay = 3600000 - time.Now.Minute * 60000 - time.Now.Second * 1000 - time.Now.Millisecond End If
timer.Interval = delay timer.Start()
End Sub
Private Sub TimerFired(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) timer.Stop() MsgBox(time.Now) SetTimer() End Sub
End Module
Max,
You do realize that instead of: delay = (span.Minutes * 60000) + (span.Seconds * 1000) + span.Milliseconds
You can use:
delay = span.TotalMilliseconds
Which will also take into account any Hours & Days in the TimeSpan.
Hope this helps
Jay
"Max" <ma*****@yahoo.com> wrote in message
news:nI********************@comcast.com... Armin Zingler wrote:
"Max" <ma*****@yahoo.com> schrieb
Ok I'm getting a hang of this and it seems to be working fine. Now here's another question, in my program the minimum time between events is 5 minuets. What do you think is better, to have the timer fire every 5 minuets and check if an event needs to be executed, or instead, counting the number of years, months, days, hours, and minuets until the next event, converting it into milliseconds, and setting that as the interval? How accurate is this thing anyway? Would it even be able to keep time for days and months or would I just be better of firing the event every 5 minuets, synchronizing it with the system time, and then starting it back up again?
I don't know how exact it is exactly, but if you use the first approach you're on the safe side.
All right guys, thanks for your help. Think I'll go with Jay’s method, there's no need to sync every 5 mins so the timer will stop and sync every hour unless an event needs to happen sooner. Below I've pasted the code of a module that I came up with. So far it seems to work fine, but I've only tested it up to an event in 5 minuets. All it does right now is give you a msgbox with the current time so you can determine if it happened when it should have. I am about to start the thing and see if it is able to correctly give me a msgbox in 1 hour 5 minuets. If you want to give it a try then simply call function "LoadTimer()" first and then call "SetTimer()", just be sure to change the value of NextEvent. Feel free to use it if you like:
Module mdlTime Private timer As New Timers.Timer Private time As Date Private span As TimeSpan Private Const NextEvent As String = "5/2/04 6:05:00 PM"
Public Sub LoadTimer() 'Call this function first in order to configure the timer AddHandler timer.Elapsed, AddressOf TimerFired timer.AutoReset = True End Sub
Public Sub SetTimer() Dim delay As Double
time = time.Parse(NextEvent) span = time.Subtract(time.Now)
'See if next event occurs within the next hour, 'otherwise set the timer to wait till the next hour of the day If span.Hours = 0 Then delay = (span.Minutes * 60000) + (span.Seconds * 1000) + span.Milliseconds Else delay = 3600000 - time.Now.Minute * 60000 - time.Now.Second * 1000 - time.Now.Millisecond End If
timer.Interval = delay timer.Start()
End Sub
Private Sub TimerFired(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) timer.Stop() MsgBox(time.Now) SetTimer() End Sub
End Module This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Ryan Spencer |
last post by:
Hello Everyone,
I want to have a row of periods, separated by small, say, .5 second
intervals between each other. Thus, for example, making it have the
appearance of a progress "bar".
...
|
by: Xaradas |
last post by:
How can I suspend the execution of a script for x seconds?
Does exists something like sleep(x)?
Thanks.
------------------------------------
"Computer Science is no more about
computers ...
|
by: Alo Sarv |
last post by:
Hi
From what I have understood from various posts in this newsgroup, writing event
loops pretty much comes down to this:
while (true) {
handleEvents();
sleep(1); // or _sleep() or...
|
by: Philip Parker |
last post by:
any ideas? sleep(1) is far too long a delay, im looking for something in the
range of 50-100 milliseconds at most.
something which doesnt suck up cpu time too much would be nice. is there
anything...
|
by: Erich Schreiber |
last post by:
In the Python Library Reference the explanation of the time.sleep()
function reads amongst others:
> The actual suspension time may be less than that requested because
> any caught signal will...
|
by: John |
last post by:
Hi all:
Is there a C function to make a procedure sleep or delay for a few
seconds/minutes on Linux and Sun OS platform?
Thanks
|
by: Max |
last post by:
This is a follow-up on my previous thread concerning having the program
wait for a certain date and time and then executing some code when it
gets there. My question is; can I use the Sleep...
|
by: jrsjrs |
last post by:
<?php
echo "<BR><BR>A) Present time is:<BR>";
echo date('h:i:s') . "\n<BR>Delaying 5 seconds, new time is:<BR>";
sleep(5);
echo date('h:i:s') . "\n<BR>";
?>
This first script delays 5...
|
by: virupax |
last post by:
Which is the best one to use sleep or delay ( for a delay in the process ) .As i understand use of sleep, allows the kernel to schedule the process.
And if a sleep of microseconds is used, and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: erikbower65 |
last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA:
1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: lllomh |
last post by:
How does React native implement an English player?
| |