Valhalla Legends Forums Archive | Visual Basic Programming | Sleep vs DoEvents

AuthorMessageTime
ObsidianWolf
I am looking to make a program that performs a task at a specified interval and was wondering if I should use the Sleep API or a DoEvents kind of Loop?

Feel Free to share Ideas.
December 13, 2003, 7:54 PM
K
[quote author=ObsidianWolf link=board=31;threadid=4216;start=0#msg35164 date=1071345270]
I am looking to make a program that performs a task at a specified interval and was wondering if I should use the Sleep API or a DoEvents kind of Loop?

Feel Free to share Ideas.
[/quote]

You should register a Timer and a callback via the CreateTimer and KillTimer API.
December 13, 2003, 8:38 PM
CupHead
Or since you're using VB, just create a timer control.
December 13, 2003, 9:41 PM
iago
timer control isn't as reliable, Grok once told me. Perhaps he can elaborate?
December 14, 2003, 1:18 AM
Grok
[quote author=iago link=board=31;threadid=4216;start=0#msg35190 date=1071364721]
timer control isn't as reliable, Grok once told me. Perhaps he can elaborate?
[/quote]

Yes.
December 14, 2003, 2:18 AM
iago
[quote author=Grok link=board=31;threadid=4216;start=0#msg35201 date=1071368326]
[quote author=iago link=board=31;threadid=4216;start=0#msg35190 date=1071364721]
timer control isn't as reliable, Grok once told me. Perhaps he can elaborate?
[/quote]

Yes.
[/quote]

Good hustle.
December 14, 2003, 2:22 AM
Grok
I do my best!
December 14, 2003, 2:25 AM
Adron
I've seen no reliability problems with the timer control, so go ahead and use that. I think it uses WM_TIMER messages which work great in C++ apps as well. They may not be the most effective thing, but they work without any trouble.
December 14, 2003, 12:35 PM
Grok
[quote author=Adron link=board=31;threadid=4216;start=0#msg35250 date=1071405320]
I've seen no reliability problems with the timer control, so go ahead and use that. I think it uses WM_TIMER messages which work great in C++ apps as well. They may not be the most effective thing, but they work without any trouble.
[/quote]

They get blocked. You miss all the events during the blocking, and receive one summary event after.
December 14, 2003, 3:22 PM
Adron
Blocked by? As in, they don't execute when the program isn't calling DoEvents often enough?
December 14, 2003, 3:48 PM
Grok
That may be the correct mechanism of failure. They're certainly not acting like asynchronous events, or at least handled as such.

When I use CreateTimer, they fire reliably without the need for DoEvents scattered throughout.
December 14, 2003, 3:55 PM
Adron
OK, an attempt to summarize:

If you want a timer to update something in your gui periodically, use a Timer control. It will only execute when your gui is allowed to update. If you don't allow your gui to update for an extended period of time, and miss several timeouts, you'll only get a single event afterwards. That way you don't do a lot of unnecessary drawing because you get 50 timer events in a row with no time between them.

If you want a timer to handle something that must be done periodically, want to get called multiple times if you've missed previous periods, and isn't related to your gui, use CreateTimer.

Does that sound about right?

Which CreateTimer call is this btw?

December 14, 2003, 4:17 PM
iago
So what somebody should do is have an API timer which calls DoEvents() to keep the GUI from screwing up while being blocked! :)
December 14, 2003, 10:14 PM

Search