Re: Delay or suspend Application waiting for thread to complete



I think I found the answer to my problem. If I use a loop that includes a
call to Application.ProcessMessages, all processes, including the timer and
threads, seem to run OK. A simple implementation is attached. A thread can
stop the delay by setting DelayObject.Timeout := 0, but there may be a
problem if the DelayObject has been destroyed because of a timeout. Any
suggestions are welcome!

I found the clue in an old web page I found at:

http://www.mindspring.com/~cityzoo/tips/tips.html

procedure TForm1.Delay(msecs:integer);
var
FirstTickCount:longint;
begin
FirstTickCount:=GetTickCount;
repeat
Application.ProcessMessages; {allowing access to other
controls, etc.}
until ((GetTickCount-FirstTickCount) >= Longint(msecs));
end;




begin 666 Delay.pas
M=6YI="!$96QA>3L-"@T*:6YT97)F86-E#0IU<V5S#0H@(%=I;F1O=W,L($UE
M<W-A9V5S+"!3>7-5=&EL<RP@0VQA<W-E<RP@4W1D0W1R;',L($5X=$-T<FQS
M+"!/<G1,:6(Q.PT*#0IT>7!E#0H@(%1/8FIE8W0Q(#T@8VQA<W,H5$]B:F5C
M="D-"B @("!4:6UE<C$Z(%14:6UE<CL-"B @("!P<F]C961U<F4@5&EM97(Q
M5&EM97(H4V5N9&5R.B!43V)J96-T*3L-"B @<')I=F%T90T*(" @('L@4')I
M=F%T92!D96-L87)A=&EO;G,@?0T*("!P=6)L:6,-"B @("![(%!U8FQI8R!D
M96-L87)A=&EO;G,@?0T*("!E;F0[#0H-"G9A<@T*("!/8FIE8W0Q.B!43V)J
M96-T,3L-"B\O("!4:6UE;W5T.B!);G1E9V5R.PT*#0IP<F]C961U<F4@(" @
M($1E;&%Y*"!C;VYS="!-<V5C.B!);G1E9V5R("D[#0H-"FEM<&QE;65N=&%T
M:6]N#0H-"G!R;V-E9'5R92 @(" @1&5L87DH(&-O;G-T($US96,Z($EN=&5G
M97(@*3L-"G9A<B @(" @(" @(" @9E1I;65R179E;G0Z(%1.;W1I9GE%=F5N
M=#L-"F)E9VEN#0H@($]B:F5C=#$@.CT@5$]B:F5C=#$N0W)E871E.PT*("!/
M<G1,:6(Q+E1I;65O=70@.CT@;5-E8SL-"B @3V)J96-T,2Y4:6UE<C$@.CT@
M5%1I;65R+D-R96%T92AN:6PI.PT*("!/8FIE8W0Q+E1I;65R,2Y);G1E<G9A
M;" Z/2 Q,# [#0H@(&94:6UE<D5V96YT(#H]($]B:F5C=#$N5&EM97(Q5&EM
M97([#0H@($]B:F5C=#$N5&EM97(Q+D]N5&EM97(@.CT@9E1I;65R179E;G0[
M#0IE;F0[#0H-"G!R;V-E9'5R92!43V)J96-T,2Y4:6UE<C%4:6UE<BA396YD
M97(Z(%1/8FIE8W0I.PT*8F5G:6X-"B @268@3W)T3&EB,2Y4:6UE3W5T(#X@
M,"!T:&5N#0H@(" @3W)T3&EB,2Y4:6UE3W5T(#H]($]R=$QI8C$N5&EM94]U
M=" M(#$P, T*("!E;'-E#0H@(" @3V)J96-T,2Y&<F5E.PT*96YD.PT*#0IE
%;F0N#0H`
`
end

.



Relevant Pages

  • Re: Exiting a windows Program?
    ... Using a forloop as a timer is a really bad idea. ... Brian ... Prev by Date: ...
    (microsoft.public.vc.language)
  • Re: Calling a procedure with loop
    ... would this not be better in a Timer ... >ProcName; ... >but break out of the loop without looping. ... Prev by Date: ...
    (alt.comp.lang.borland-delphi)
  • Re: Using queues with DAQ cards and general programing???
    ... Similar to what I said for A. Destroy the task when you leave the loop. ... Add a wait timer in all loops so they do not run too fast and goble up all of the CPU. ... Prev by Date: ...
    (comp.lang.labview)
  • Re: FMSMCSE finally gone.
    ... - Programmers don't repeat themselves, they LOOP. ... Prev by Date: ...
    (microsoft.public.cert.exam.mcse)
  • code loops 1024 times not what i ask
    ... I wonder if someone can help, I am trying to repeat some code 200 times can ... you tell me where I am going wrong in my loop. ... Sub test() ... Prev by Date: ...
    (microsoft.public.excel.programming)