formi
asked on
Thread in Delphi - time-problem
Hi
In an application I comunicate with a mobile device. If the device is not in the dockingstation it is possible, that calling a function will respond after a timeout of i.e. 60 seconds. So my idea was to program this in a thread.
In an application I comunicate with a mobile device. If the device is not in the dockingstation it is possible, that calling a function will respond after a timeout of i.e. 60 seconds. So my idea was to program this in a thread.
TPdaSyncThread = class(TThread)
private
procedure doProcess;
protected
procedure Execute; override;
public
constructor Create(... myParams);
end;
constructor TPdaSyncThread.Create(... myParams);
begin
FreeOnTerminate := True;
inherited Create(False);
....
end;
procedure TPdaSyncThread.doProcess;
begin
Sleep(30000); //just to "simulate" calling the function that will return after a timeout
end;
procedure TPdaSyncThread.Execute;
begin
while not Terminated do
begin
Synchronize(self,doProcess);
end;
end;
In the main-thread I have a procedure "AppMessage" (Application.Onmessage := "AppMessage". During the 30 seconds (sleep) this procedure is never called. I think I didn't understand something with threading??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes you are right. it only sleeps - as I wrote in the code's comment to simulate the long answer-time of a routine. But I think you gave me the tip: is it correct that during calling a routine with "Synchronize" no other thread gets time to execute? If "Yes" I have to call the time-consuming routines in the execute-loop and not in the synchronize-routine.
ASKER
Thanks you helped me both!
make sure all procedures in synchronize are short
and don't update/draw anything on other forms from inside a thread
you'll have circular unit reference to start with
the code may be simple but it will difficult to follow the flow of just 1 unit
and don't update/draw anything on other forms from inside a thread
you'll have circular unit reference to start with
the code may be simple but it will difficult to follow the flow of just 1 unit
the only thing this thread does is sleep ... every 30 seconds