sparklin
asked on
Multi Threading???
I've created a simple TThread object that downloads a file via FTP protocol. Everything seems to be working fine except that the main form is very sluggish while threads are running. Also threads tend to freeze system at end of downlaod. Any help or pointers to thread documentation would be appreciated.
Here's the code:
unit uFtpThread;
interface
uses
Classes, agFtp, agFTPCls;
type
TFtpThread = class(TThread)
private
FTargetFileName : String;
FLocalFileName : String;
FFtp : TagFtp;
procedure DownloadFile;
protected
procedure Execute; override;
public
constructor create(Ftp : TagFtp; sTargetFilename, sLocalFileName : String);
end;
implementation
constructor TFtpThread.create(Ftp: TagFtp; sTargetFilename,
sLocalFileName: String);
begin
inherited Create(False);
FreeOnTerminate := True;
FFtp := Ftp;
FTargetFileName := sTargetFilename;
FLocalFileName := sLocalFileName;
end;
procedure TFtpThread.DownloadFile;
begin
FFtp.RetrieveFile(FTargetFileName, FLocalFileName);
end;
procedure TFtpThread.Execute;
begin
DownloadFile;
end;
end.
Here's the code:
unit uFtpThread;
interface
uses
Classes, agFtp, agFTPCls;
type
TFtpThread = class(TThread)
private
FTargetFileName : String;
FLocalFileName : String;
FFtp : TagFtp;
procedure DownloadFile;
protected
procedure Execute; override;
public
constructor create(Ftp : TagFtp; sTargetFilename, sLocalFileName : String);
end;
implementation
constructor TFtpThread.create(Ftp: TagFtp; sTargetFilename,
sLocalFileName: String);
begin
inherited Create(False);
FreeOnTerminate := True;
FFtp := Ftp;
FTargetFileName := sTargetFilename;
FLocalFileName := sLocalFileName;
end;
procedure TFtpThread.DownloadFile;
begin
FFtp.RetrieveFile(FTargetFileName, FLocalFileName);
end;
procedure TFtpThread.Execute;
begin
DownloadFile;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER