Refer to: How to animate a spinner while performing a workload via threading
I am working with a Delphi xe5 Application for iOS. While performing a SQL query, I have a TAniIndicator spinning. I am using threads - for specific code, see article stated above.
Everything works, however, when using the code I was helped with in the previous question, I've noticed added lag. When ran under the debugger, the application hangs between the lines:
Thread.DoTerminate;
Thread.FFinished := True;
under the ThreadProc Function of System.Classes Unit
Any clue as to why ? Or what I can do to prevent that added 5 second lag? Thank you
Update reply to TLama:
procedure TForm_Login.WorkIsDone(Sender : TObject);
begin
Form_Login.LoadSpinnerFrame.visible := False;
Form_Login.LoadSpinner.Visible := False;
Form_Login.LoadSpinner.Enabled := False;
Form_Login.btnLogin.Text := 'Logout';
Form_Login.btnLogin.Enabled := True;
if GoodLogin = 1 then
Main_Form.show;
end;
My onTerminate() is linked to the above procedure.
TThread.DoTerminate() calls TThread.Synchronize() to fire the TThread.OnTerminate event handler in the main thread. TThread is then blocked until the main thread processes that request - which does not happen instantaneously as the main thread has to detect and process new messages first - and the OnTerminate handler exits. Only then is control returned to TThread so it can finish its logic. So if you are encountering a 5s lag in DoTerminate(), then it mean the main thread is taking 5s to detect and process the Synchronize() request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With