Home > Back-end > Delphi why execution time delay function can't close the window?
Delphi why execution time delay function can't close the window?
Time:09-24
Online to find a don't hang don't delay function of the CPU, in use process, found the loop can't close the window, By rights added: Application. ProcessMessages; Not should be able to respond to other message? Why can't the news of the response to close the window? Looked great god help solve, thank you very much! Delphi2010
Function parts:
Procedure TForm2. Delay (msecs: integer);//super delay Var Tick: DWord; Event: THandle; The begin Event:=CreateEvent (nil, False, False, nil); Try Tick:=GetTickCount + dwords (msecs); While (msecs & gt; 1, 0) and (MsgWaitForMultipleObjects (Event, False, msecs, QS_ALLINPUT) & lt;> WAIT_TIMEOUT) do The begin Application. ProcessMessages;//handle events () Msecs:=Tick - GetTickcount; end; The finally The CloseHandle (Event); end; end;
Application part (click on the button here, after the loop is not performed can't close the window) :
Procedure TForm2. Button3Click (Sender: TObject); Var I: Integer; The begin I:=0; For I:=0 to 10 do The begin ShowMessage (IntToStr (I)); Delay (2000); end; end;
CodePudding user response:
Don't recommend you this kind of writing, don't hang don't delay function of the CPU, please use the timer,