|
-
Apr 23rd, 2013, 01:03 PM
#1
Thread Starter
Lively Member
Self-toggling timer
Hi ! I need help with this, because i cant think anything that would do this.
I have a timer with interval of 1ms and it does some work, and now i want to make it:
Turn on and do the work for 500ms (no not the interval 500ms, but the timer has to be toggled for 500 milliseconds) and after those 500 ms it has to turn off for next 500ms, then it turns on back etc.So its like:
Turn on -> do the work -> after 500 ms turn off (.Enabled = False) -> stay turned off for 500 ms -> Turn on..
How can i do it ? I cant think anything
-
Apr 23rd, 2013, 01:42 PM
#2
Re: Self-toggling timer
use 2 timers. The first timer is set to your 1ms interval and the second set to 500ms. In the tick event of the second timer toggle the enabled bit of the first timer using Timer.enabled = Not Timer1.Enabled
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Apr 23rd, 2013, 02:29 PM
#3
Re: Self-toggling timer
I have a timer with interval of 1ms
No. you have a timer set for an interval of 1ms. The chances that it's actually firing at 1ms intervals is absolutely zero. Microsoft recommends a minimum interval of 35ms. most people 50ms and me 100ms. At best you'll get inconsistent performance, at worst you'll crash the event queue. Either way it's really not worth it. If you really need something to happen 1000 times a second (and that's extremely unlikely) then you should use one of the other VB timer classes.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 23rd, 2013, 02:57 PM
#4
Re: Self-toggling timer
 Originally Posted by dunfiddlin
No. you have a timer set for an interval of 1ms. The chances that it's actually firing at 1ms intervals is absolutely zero. Microsoft recommends a minimum interval of 35ms. most people 50ms and me 100ms. At best you'll get inconsistent performance, at worst you'll crash the event queue. Either way it's really not worth it. If you really need something to happen 1000 times a second (and that's extremely unlikely) then you should use one of the other VB timer classes.
A good example of this is a game loop. Generally new programmers use a Timer and set it's interval to really low(like 1ms), the problem with that is just like dunfiddlin described; the event queue gets all jacked up. Also while Kebo's suggestion may work, the more timers there are running at the same time, the worse they get. So my point I'm trying to get across is, you should probably look into redesigning what you're trying to accomplish. Why don't you tell us what you're trying to accomplish, there maybe a better way of doing what you're trying.
-
Apr 23rd, 2013, 03:46 PM
#5
Re: Self-toggling timer
The question isn't clear. If "do the work" isn't UI intensive I'd just get rid of the timer altogether and use a separate thread with appropriate sleeps.
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
|