A
asksomeone
Unregistered / Unconfirmed
GUEST, unregistred user!
const
WM_netthDone=wm_user+203;
type
Netthread = class(TThread) {网络连接线程}
private
Fhandle:HWND;
procedure changcolor;
protected
procedure Execute;
override;
public
constructor Create(CreateSuspended: Boolean;AHandle:HWND);
destructor Destroy;override;
end;
private
procedure NetthDone(var Message:TMessage);message WM_netthDone;
{上面是摘出来的}
{调用IdIcmp的ping方法查看网络是否正常}
Function net_Ping(IpAddress:String):Boolean;
begin
try
f_main.IdICMP.ReceiveTimeout := 500;
f_main.IdICMP.Host := IpAddress;
f_main.IdICMP.Ping;
{调用方法Ping;}
Application.ProcessMessages;
case f_main.IdICMP.ReplyStatus.ReplyStatusType of
rsTimeout:Result:=False;
else
Result:=True;
end;
finally end;
{异常处理 }
end;
{监测网络状态线程开始}
constructor netthread.Create(CreateSuspended:boolean;AHandle:HWND);
begin
inherited Create(CreateSuspended);{false是指构造的同时即唤醒}
FreeOnTerminate := True;
FHandle:=AHandle;
Resume;
end;
destructor netThread.Destroy;
begin
inherited;
end;
procedure netThread.changcolor;
var
icoindex:integer;
begin
f_main.reconn.Caption:='连接正常';
f_main.reconn.ShowHint:=false;
Randomize;
icoindex:=random(2);
f_main.ImageList1.GetIcon(icoindex,f_main.Image1.Picture.icon);
Screen.Cursor := CrDefault;
end;
procedure netThread.Execute;
begin
if (self.terminated)then
exit;
try
Synchronize(changcolor);
PostMessage(FHandle,WM_netthDone, Self.ThreadID,0);
closehandle(fhandle);********************************
except
on E:Exceptiondo
begin
PostMessage(FHandle,WM_netthDone, Self.ThreadID,MaxInt);
closehandle(fhandle);********************************
end;
end;
end;
procedure Tf_main.netthDone(var Message:TMessage);
begin
if message.msg=wm_netthDone then
begin
netthen
d:=true;{标识一个线程的结束}
end;
end;
procedure TF_main.Timer3Timer(Sender: TObject);
begin
if(Net_Ping('222.35.22.78')=true) and(flagx=0)and(netthen
d=true) then
begin
netthen
d:=false;{线程开始标识为false}
Netthread.Create(true,f_main.Handle);
end;
end;
我想问带*****的地方释放传入的句柄
1、需不需要?
2、方法对不对?是用closehandle(),还是用freeandnil()方法对?
3、(重要的,我最关心的)还有没有漏洞,就是是不是有句柄没有被释放完?(如果释放完了,但我的程序里面内存没问题线程也没变化,就是句柄数再增加)
大哥们,小弟急盼回贴!在线等
WM_netthDone=wm_user+203;
type
Netthread = class(TThread) {网络连接线程}
private
Fhandle:HWND;
procedure changcolor;
protected
procedure Execute;
override;
public
constructor Create(CreateSuspended: Boolean;AHandle:HWND);
destructor Destroy;override;
end;
private
procedure NetthDone(var Message:TMessage);message WM_netthDone;
{上面是摘出来的}
{调用IdIcmp的ping方法查看网络是否正常}
Function net_Ping(IpAddress:String):Boolean;
begin
try
f_main.IdICMP.ReceiveTimeout := 500;
f_main.IdICMP.Host := IpAddress;
f_main.IdICMP.Ping;
{调用方法Ping;}
Application.ProcessMessages;
case f_main.IdICMP.ReplyStatus.ReplyStatusType of
rsTimeout:Result:=False;
else
Result:=True;
end;
finally end;
{异常处理 }
end;
{监测网络状态线程开始}
constructor netthread.Create(CreateSuspended:boolean;AHandle:HWND);
begin
inherited Create(CreateSuspended);{false是指构造的同时即唤醒}
FreeOnTerminate := True;
FHandle:=AHandle;
Resume;
end;
destructor netThread.Destroy;
begin
inherited;
end;
procedure netThread.changcolor;
var
icoindex:integer;
begin
f_main.reconn.Caption:='连接正常';
f_main.reconn.ShowHint:=false;
Randomize;
icoindex:=random(2);
f_main.ImageList1.GetIcon(icoindex,f_main.Image1.Picture.icon);
Screen.Cursor := CrDefault;
end;
procedure netThread.Execute;
begin
if (self.terminated)then
exit;
try
Synchronize(changcolor);
PostMessage(FHandle,WM_netthDone, Self.ThreadID,0);
closehandle(fhandle);********************************
except
on E:Exceptiondo
begin
PostMessage(FHandle,WM_netthDone, Self.ThreadID,MaxInt);
closehandle(fhandle);********************************
end;
end;
end;
procedure Tf_main.netthDone(var Message:TMessage);
begin
if message.msg=wm_netthDone then
begin
netthen
d:=true;{标识一个线程的结束}
end;
end;
procedure TF_main.Timer3Timer(Sender: TObject);
begin
if(Net_Ping('222.35.22.78')=true) and(flagx=0)and(netthen
d=true) then
begin
netthen
d:=false;{线程开始标识为false}
Netthread.Create(true,f_main.Handle);
end;
end;
我想问带*****的地方释放传入的句柄
1、需不需要?
2、方法对不对?是用closehandle(),还是用freeandnil()方法对?
3、(重要的,我最关心的)还有没有漏洞,就是是不是有句柄没有被释放完?(如果释放完了,但我的程序里面内存没问题线程也没变化,就是句柄数再增加)
大哥们,小弟急盼回贴!在线等