I'm using telnet client in my app, to access streaming market data.
It works ok for Windows and iOS, but on Android the app hangs
for several seconds when telnet.Disconnect is called. So much that
Android detects the app is stalled and terminates it.
I understand that Connect and Disconnect can block the
execution, so they are not to be called from the UI thread.
But why Disconnect takes so long ?
One guy suggested on stackoverflow that the reader thread
was locked or not finishing, and that blocked the Disconnect call.
So I tried to create a thread dedicated to disconnect.
It seems to work
It works ok for Windows and iOS, but on Android the app hangs
for several seconds when telnet.Disconnect is called. So much that
Android detects the app is stalled and terminates it.
I understand that Connect and Disconnect can block the
execution, so they are not to be called from the UI thread.
But why Disconnect takes so long ?
One guy suggested on stackoverflow that the reader thread
was locked or not finishing, and that blocked the Disconnect call.
So I tried to create a thread dedicated to disconnect.
It seems to work

Code:
procedure TForm1.ThreadedTelnetDisconnect;
var aThreadDisconnect:TThread;
begin
aThreadDisconnect := TThread.CreateAnonymousThread(
procedure begin
IdTelnet1.Disconnect;
end);
aThreadDisconnect.start();
end;