to g622:
下面是我写的一个测试程序
阻塞的Socket不会死机,线程结束也不会死机,
只要是
在县城中打开了一个ctNonBlocking 的ClientSocket
然后线程挂起或空转,
这时,切换输入法酒会死机。
是不是 Socket 跟消息处理或线程有关?
Pwin2000 + delphi5
代码如下:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TmyThread = class( TThread)
protected
procedure execute ;
override;
end;
var
Form1: TForm1;
t: TMythread;
socket: TClientSocket;
implementation
{$R *.DFM}
{ TmyThread }
procedure TmyThread.execute;
begin
socket.active := true;
while truedo
sleep(1);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
t := Tmythread.create(false);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
socket := TClientsocket.Create(nil);
socket.address :='200.200.200.200';
socket.port := 110;
socket.ClientType := ctnonBlocking;
// ????
end;
end.