i this same code . entire code here
formcreate
If Not Assigned(MonThread) Then Begin
MonThread:=TMonThread.Create(False);
{$IFDEF WIN32}
MonThread.Priority:=tpTimeCritical;
{$ENDIF}
End;
// -----------------------------------------------------------------------------
procedure TMonThread.Execute();
begin
While Not Terminated Do Begin
Try Try
//Synchronize(nil,
Queue(nil, // Queue è asincrono e 'refresha' meglio di Synchronize
Procedure
Begin
cgLTOUsc.Value:=StrToIntDef(frmTDPComPort.MonValues.Strings[lstLTO_USC_CORR],0);
// visualizza il valore in dettaglio
cgLTOUsc.DisplayText:=frmTDPComPort.MonValues.Strings[lstLTO_USC_CORR];
cgTDS.Value:=StrToIntDef(frmTDPComPort.MonValues.Strings[lstTDS_CORR],0);
// visualizza il valore in dettaglio
cgTDS.DisplayText:=frmTDPComPort.MonValues.Strings[lstTDS_CORR];
End);
End;
Except
On E:Exception Do Begin
If Assigned(MonThread)Then Begin
MonThread.Terminate();
MonThread.WaitFor();
FreeAndnil(MonThread);
End;
End;
End;
Finally
// fa qualcosa
End;
Sleep(100); // per evitare l'uso intensivo di CPU
End;
end;
// -----------------------------------------------------------------------------
Function TfrmTDPMon.CloseForm
Begin
If Assigned(MonThread)Then Begin
MonThread.Terminate();
MonThread.WaitFor();
FreeAndnil(MonThread);
End;
NOTE : circular objects not destroyed on CloseForm, form is always alive !