• Welcome to Valhalla Legends Archive.
 

Sleep vs DoEvents

Started by ObsidianWolf, December 13, 2003, 01:54 PM

Previous topic - Next topic

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.

K

Quote from: ObsidianWolf on December 13, 2003, 01:54 PM
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.

You should register a Timer and a callback via the CreateTimer and KillTimer API.

CupHead

Or since you're using VB, just create a timer control.

iago

timer control isn't as reliable, Grok once told me.  Perhaps he can elaborate?
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Grok

Quote from: iago on December 13, 2003, 07:18 PM
timer control isn't as reliable, Grok once told me.  Perhaps he can elaborate?

Yes.

iago

Quote from: Grok on December 13, 2003, 08:18 PM
Quote from: iago on December 13, 2003, 07:18 PM
timer control isn't as reliable, Grok once told me.  Perhaps he can elaborate?

Yes.

Good hustle.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Grok


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.

Grok

Quote from: Adron on December 14, 2003, 06:35 AM
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.

They get blocked.  You miss all the events during the blocking, and receive one summary event after.

Adron

Blocked by? As in, they don't execute when the program isn't calling DoEvents often enough?

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.

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?


iago

So what somebody should do is have an API timer which calls DoEvents() to keep the GUI from screwing up while being blocked! :)
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*