procedure TForm1.N3Click(Sender: TObject);
var
j :integer;
begin
IdTCPServer1.Threads.UnlockList;
for j := 0 to IdTCPServer1.Threads.LockList.Count-1 do
begin
TIdPeerThread(IdTCPServer1.Threads.LockList.Items[j]).Connection.DisconnectSocket;
IdTCPServer1.Threads.UnlockList;
end;
IdTCPServer1.Threads.LockList.Clear;
IdTCPServer1.Threads.UnlockList;
IdTCPServer1.Active:=false;
N3.Enabled := False;
N2.Enabled := True;
RzMemo1.Lines.Add('服务已停止。');
end; 以上代码经过多次实验,在有客户端连接的状态下关闭服务没有问题,但在刚启动服务马上关闭服务时会出现屏幕假死,问题主要出现在IdTCPServer1.Threads.LockList.Count这个上,请各位大侠如何解决? 用的D7 自带的indy
var
j :integer;
begin
IdTCPServer1.Threads.UnlockList;
for j := 0 to IdTCPServer1.Threads.LockList.Count-1 do
begin
TIdPeerThread(IdTCPServer1.Threads.LockList.Items[j]).Connection.DisconnectSocket;
IdTCPServer1.Threads.UnlockList;
end;
IdTCPServer1.Threads.LockList.Clear;
IdTCPServer1.Threads.UnlockList;
IdTCPServer1.Active:=false;
N3.Enabled := False;
N2.Enabled := True;
RzMemo1.Lines.Add('服务已停止。');
end; 以上代码经过多次实验,在有客户端连接的状态下关闭服务没有问题,但在刚启动服务马上关闭服务时会出现屏幕假死,问题主要出现在IdTCPServer1.Threads.LockList.Count这个上,请各位大侠如何解决? 用的D7 自带的indy
TerminateListenerThreads;
TerminateAllThreads;可参考 http://topic.csdn.net/u/20090815/11/752660bf-9b0a-474f-b45e-0426d97ce874.html