|
-
Dec 10th, 2009, 05:25 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How to make the program loop and sleep
hi
how to make program loop the job and after that sleep for 15 min
and after 15 min start again and do the job and after that sleep again
-
Dec 10th, 2009, 05:31 AM
#2
Re: How to make the program loop and sleep
try using a timer to keep track of the current system time and preform operation every 15 minutes
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 10th, 2009, 05:42 AM
#3
Thread Starter
Addicted Member
Re: How to make the program loop and sleep
-
Dec 10th, 2009, 05:59 AM
#4
Re: How to make the program loop and sleep
in your timer event
vb Code:
Static startime As Date If startime = "12:00:00 AM" Then startime = Now 'to set a value first timer run If Now > startime Then dostuff ' run some other procedure startime = DateAdd("n", 15, Now) 'reset startime 15 minutes later
you can set the timer interval to approx 1 minute (60000)
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Dec 10th, 2009, 12:44 PM
#5
Thread Starter
Addicted Member
Re: How to make the program loop and sleep
is run with time
i want it the program run every 15 min and sleep 15 and run again
hope u got it
-
Dec 10th, 2009, 12:50 PM
#6
Re: How to make the program loop and sleep
Have you tried the code? Add a timer to your form and copy & paste sample code as suggested.
-
Dec 10th, 2009, 04:21 PM
#7
Thread Starter
Addicted Member
Re: How to make the program loop and sleep
i did it and if the time is not 12:00:00 the code not running
i must put time with it like run my program in after 15 when time will be 2:00:00 PM
and i want it like this
i want my program do his job and sleep for 15 min and do his job again ....etc
i hope u got it
-
Dec 10th, 2009, 04:29 PM
#8
Re: How to make the program loop and sleep
With the code that westconn1 provided, the 1st time the timer event is triggered, it will set the 15 minute marker exactly 15 minutes later, then "do stuff" when that marker elapses, set the next 15 minute marker, etc, etc. Did you enable your timer and give it a non-zero interval? If not, do that.
Here is another option if you want to dictate when the 1st event will occur or you start/stop your timer.
1. Declare a new variable at top of your form: Dim targetTime As Date
2. Be sure to set your timer's interval property to something like 30 seconds. Enabled=False
3. In your button click or whatever you use to start/stop the timer
:: When starting, set targetTime to the date/time when the 1st event should be run and enable your timer
:: When stopping, disable your timer
4. The timer event would look like this
Code:
If Now() => targetTime Then
' disable the timer
' call your routine that must be run
targetTime = DateAdd("n", 15, Now())
' re-enable the timer
End If
As you can see there isn't much difference between the 2 methods.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|