不知为何我的线程老是半途出错??!

lbsoft 2001-07-07 11:41:28
我的代码如下:unit Unit15;

interface

uses
Windows,Classes,Sysutils;

type
TCheckUrl = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
constructor Create;
end;

implementation

uses
Unit2,Unit3;

constructor TCheckUrl.Create;
begin
inherited Create(true);
end;

procedure TCheckUrl.Execute;
var
CurTime:LongWord;
DelayTime:LongWord;
Tag_Value:integer;
Address_Chk:string;
begin
with CheckLinksForm.DBISAMTable do
begin
TableName:='UrlAddress.dat';
Exclusive:=False;
ReadOnly:=False;
Open;
First;
while not EOF do
begin
Url_True_False:=False;
Address_Chk:=MainForm.DenCrypt(Trim(FieldByName('Url').AsString),'');
if Address_Chk<>'' then
begin
try
CheckLinksForm.NMhttp1.head(Trim(Address_Chk));
//设置时间延迟为0.5秒
DelayTime:=5000;
CurTime:=GetTickCount;
while (GetTickCount<(CurTime+DelayTime)) do
if Url_True_False=True then break;
CheckLinksForm.NMhttp1.Cancel;
if Url_True_False=True then
begin
Address_Chk:=Address_Chk+' ......Ok!';
CheckLinksForm.Memo1.Lines.Add(Address_Chk);
Tag_Value:=2;
end
else
begin
Address_Chk:=Address_Chk+' ......Failure!';
CheckLinksForm.Memo1.Lines.Add(Address_Chk);
Tag_Value:=1;
end;
except
Url_True_False:=False;
Address_Chk:=Address_Chk+' ......Failure!';
CheckLinksForm.Memo1.Lines.Add(Address_Chk);
Tag_Value:=1;
end;
//fieldbyname('Tag').value:=Tag_Value;
//fieldbyname('M_Date').value:=DatetimeToStr(Now);
//Post;
end;
next;
if Terminated then Exit;
end;
end;
CheckLinksForm.button2.caption:='Finished';
end;

end.
...全文
61 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lbsoft 2001-07-07
  • 打赏
  • 举报
回复
能不能再详细一点?
Crob 2001-07-07
  • 打赏
  • 举报
回复
type
TCheckUrl = class(TThread)
private
{ Private declarations }
//要在这个位置声明线程内的资源对象
protected
procedure Execute; override;
public
constructor Create(xxx : xxx); //重载TThread的Create,在这里进行参数及线程资源的初始化工作
end;

线程结束后会释放所有在线程内声明的资源

Crob 2001-07-07
  • 打赏
  • 举报
回复
可能是线程内的资源发生异常导到线程退出。

我看你在线程中使用的FieldByName('xxx')之类的数据库对象,可能这里会有问题。
还有所有线程不要共用CheckLinksForm.NMhttp1之类的同一个对象,要在线程中创建实例。否则所有线程共用一个实例会发生冲突。

总之,你的线程中的线程资源问题好象很多。
lbsoft 2001-07-07
  • 打赏
  • 举报
回复
关注!

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧