Delphi简单的TCP服务器挂起.表单冻结但服务器继续管理客户端

Boo*_*reg 2 delphi tcp

我正在使用带有IdTCPServer的表单来管理来自客户端的字符串和AThread.connection.readln/writeln系统.字符串处理工作,这不是问题.

问题是,服务器上的表单挂起并且不会加载,但它仍然管理连接到它的所有客户端,因此它正在运行但它不能用作表单.我会猜测它坐在阅读线上还是什么东西......但是我不知道如何在这个时刻解决这个问题.

请帮忙.

procedure TMonitorFrm.ServerExecute(AThread: TIdPeerThread);

    procedure post(PostMessage:string);
    begin
            try
                    AThread.Connection.WriteLn(PostMessage);
            except
                    showmessage('Cannot post');
            end;
    end;

var
        ActClient       : PClient;
        sTemp,
        CommBlock,
        NewCommBlock,
        ReceiverName,
        sContent,
        sSQL,
        sCommand        : String;
        iCount2,
        iCount          : Integer;

        sldb    : TSQLiteDatabase;
        sltb    : TSQLiteTable;

begin
        if not AThread.Terminated and AThread.Connection.Connected then
        begin
                CommBlock := AThread.Connection.ReadLn();
                ActClient := PClient(AThread.Data);
                ActClient.LastAction := Now;
                sCommand := copy(CommBlock,0,pos(',',CommBlock)-1); {seperate command}
                sContent := copy(CommBlock,pos(',',CommBlock)+1,length(CommBlock)-(pos(',',CommBlock)+1)); {seperate data block}
                iCount:= 0 ;

            if sCommand = 'Announce' then //SPECIAL
            begin
                    { Do stuff for this command...}
            end

            else if sCommand = 'CheckSect' then
                    {Etcetera...}

procedure TMonitorFrm.FormCreate(Sender: TObject);
var
        sCompetitionID  : string;
        sldb    : TSQLiteDatabase;
        sltb    : TSQLiteTable;
begin
        Clients := TThreadList.Create;
        Server.Active := True;
        AreaPnlList := TComponentList.Create;
        SectionPnlList := TComponentList.Create;
        Repeat until InputQuery('Competition Select', 'Please type the ID of the competition', sCompetitionID);
        iCompetitionID:=StrToInt(sCompetitionID);
        OpenDatabase(slDb);
        sltb:=slDb.GetTable('SELECT * FROM SectionTable WHERE CompetitionID='+sCompetitionID);
        Frame31.CreateSections(sltb,Frame31);
        sltb.Free;
        CloseDatabase(slDb);
{
This section needs to check the SQLite databases for sections and list them in the display window and makes a drag n drop profile...
}
end;
Run Code Online (Sandbox Code Playgroud)

Rob*_*edy 6

Indy使用阻塞套接字.它应该挂起当前线程.要在VCL线程中使用Indy组件同时保持VCL线程响应,TIdAntifreeze还要在表单上放置一个组件.Indy组件知道该组件并将定期对其进行控制,以便您的VCL线程可以继续处理消息.