Re: Re-entrancy???

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Let's see...

"Bill McCarthy" <Bill@xxxxxxxxxxxxx> escribió en el mensaje
news:ejq8yi6TJHA.2468@xxxxxxxxxxxxxxxxxxxxxxx

"Eduardo" <mm@xxxxxx> wrote in message news:ggip74$819$1@xxxxxxxxxxx
"Bill McCarthy" <Bill@xxxxxxxxxxxxx> escribió en el mensaje
news:uoNy$V3TJHA.3648@xxxxxxxxxxxxxxxxxxxxxxx

There is absolutely no reason to add a sleep statement if he is using
DoEvents statements. A sleep request actually pauses his thread
prematurely, forcibly, whether it is needed or not. A DoEvents checks
the message pump and allows for the app to yeild.

I don't know in what you base that point of view, but i think that you
are completely wrong here.


Well we might have to agree to disagree. Usually I find PLC's return data
very quickly, and if the concept is to have as close to real time as
possible, then adding Sleep is detrimental to the program.

If you are comunicating _two or more_ devices in real time, yes.
But for that task i think that a microcontroller would be more appropiate,
not a PC.
In Windows you can't response in real time even if you want, because of the
multitasking. Even without Sleep, if you need a fast response all the times,
you can't do it in Windows because of the multitasking. At least not in a
"normal" program. With drivers and services may be perhaps.

But i guess that this is not the case of the OP.
If one milisecond is a problem, you are fried using a PC with Windows.
The data wont be lost because the comunication protocol for sure has a
buffer and a handshake.


Larry's recommendation to add a Sleep 1 doesn't free up system resources
anymore than the existing DoEvents.


As i pointed before, Doevents and Sleep do completely different things.
There is nothing in common between the two functions.



Right which is also what I said. Sleep forces your thread to pause
regardless of what other system resources are needed or not.

The resources are usually needed.


In his particular case the best is to use both.
Doevents doesn't replace Sleep, and Sleep doesn't replace Doevents.



Nope. That might be true if he needs to deliberately insert a delay, but
he has made no mention of that.
And if he was to insert a delay it would NOT be Sleep 1.

What would you insert? I'm curious.


Also:

A sleep request actually pauses his thread prematurely, forcibly,
whether it is needed or not.

As i pointed before too, in loops that have to wait for something to
happen, Sleep (or a similar function if does exists one) is a necessity.


DoEvents will yeild the porocess to windows tasking.

I don't think so.




pauses his thread prematurely, forcibly, whether it is needed or not.

If the event that it is waiting didn't happen, then is a need to wait.


yes but how long.

1 milisecond, i already told.


Usually with PLC's it's just a matter of clock cycles.

With Windows you are fried. Use D.O.S. or a microcontroller instead.


If it was a series of events that actually takes some delay,

It seems that at least sometimes, it takes more than a second, because the
timer is ticking again (that was the original problem).


I assume the
original poster, at least from what he has said and shown here, would be
smart enough to add a delay.

¿¿??


That of course is a different thing from saying add a Sleep 1 to your loop
on top of DoEvents, which is completely wrong.

OK, tell me your recipe. May be i learn something.


You can wait sitting on a chair (Sleep) or running around the table
(without Sleep). But running arount the table will be a waste of energy
because you don't do anything useful (yeah, you do exercise, but the
processor doesn't need to exercise).


Sure, but you're still making the presumption there is a significant time
delay before a response is given

Answered already two times in this post i'm writing now.


.



Relevant Pages

  • Re: Re-entrancy???
    ... The minimal pause is set by the system clock resolution. ... This is to do with windows bascially getting the count of ticks and seeing if it is larger than the interval you specified. ... The facts remains you said you need to call Sleep 1 along with the DoEvents, when reality is you do not. ...
    (microsoft.public.vb.general.discussion)
  • Re: Re-entrancy???
    ... know about the need to change the timer interval. ... I really didn't think that he was doing a critical process in real time. ... The OP wasn't against the use of Sleep, but he undestood that using Sleep ... means to remove Doevents. ...
    (microsoft.public.vb.general.discussion)
  • Re: Re-entrancy???
    ... Sleep calls will just slow the application down. ... Whether or not PeekMessage is occuring in DoEvents ... has no impact on the overall CPU utilization. ... correctly, using the timeXXXX-APIs. ...
    (microsoft.public.vb.general.discussion)
  • Re: Batch file and MFC (Properly Terminating Application)
    ... I have a function called DoEvents ... Sleep fucntion is within that loop as well as DoEvents ... while(!GetQueuedCompletionStatus(port, &bytes, &key, timeout)) ... if timeout also check for abort ...
    (microsoft.public.vc.mfc)
  • Re: Query Unload issues
    ... Sleep kills your app for the duration specified. ... This is the opposite to DoEvents, ... due to the loop, which would not be required if you redesigned the ... If blnStop = True Then Exit Do ...
    (microsoft.public.vb.general.discussion)