中国开发网: 论坛: 程序员情感CBD: 贴子 90681
haitao
技术贴.delphi.socket:这段代码会导致程序占100%cpu,而且无法kill!!
技术贴.delphi.socket:这段代码会导致程序占100%cpu,而且无法kill!!
如果在delphi里运行,关delphi才可以结束程序,一般的run-reset都不行
如果独立运行,只有重启机器了
--用任务管理器杀,现象与一般的能杀成功的程序一样,但是就是最后它依然占100%cpu地运行

procedure TFrameCer.BBtnConnectClick(Sender: TObject);
begin
step:=1;
if Cer.Active then //Cer: TClientSocket;
Begin
Cer.Active:=false;
if Cer.Active then
//这里比较奇怪吧:因为我发现有时候,Cer.Active:=false这样是断不掉的
//此时Cer.Socket.SocketHandle==-1
//也不知道怎么导致的,而且怎么也恢复不正常了,只有free掉再建
Begin
log('!!Cer.Cannot DisActive!!',true);
//exit;

Cer.free;
Cer:=TClientSocket.Create(self);
Cer.ClientType:=ctNonBlocking;
Cer.OnConnecting:=Self.CerConnecting;
Cer.OnConnect:=Self.CerConnect;
Cer.OnDisconnect:=Self.CerDisconnect;
Cer.OnRead:=Self.CerRead;
Cer.OnError:=Self.CerError;
//但是有可能free或再建时出错了,导致100%cpu和无法杀
End;
End;
//Cer.Socket.Disconnect(Cer.Socket.SocketHandle);
//exit;
Cer.Address:=Eip.Text;
Cer.Port:=SEport.value;
log('ConnectTo:'+Cer.Address+':'+inttostr(Cer.Port));
try
Cer.Active:=true;
except on e:exception do
//htdebug.debuglog('!Exception:'+e.Message);
end;
BtnOK(true);
end;
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录