Hi Guys, i'm having problems with an android-app.

Hi Guys, i'm having problems with an android-app.

I have different threads and i have to know within my procs/funcs if i'm in mainthread or not, so i have decided to create following proc:

procedure RunSynchronized(vMethod:TThreadProcedure);
var
vt:boolean;
begin
vt:=false;
if tThread.CurrentThread<>nil then begin
if (tThread.CurrentThread.ThreadID<>MainThreadID) then begin
vt:=true;
end;
end;

if tThread.Current<>nil then begin
if (tThread.Current.ThreadID<>MainThreadID) then begin
vt:=true;
end;
end;

if vt=false then begin
vmethod();
end else begin
tThread.Synchronize(nil, vmethod);
end;
end;

so i can use:
RunSynchronized(procedure begin
do something here;
end);

Is this the correct way? It seems that i have under Seattle 10 with android sometimes problems getting MainThreadId because some calls are causing a app hang ...

Comments