| View previous topic :: View next topic |
| Author |
Message |
Jacky Guest
|
Posted: Thu Apr 22, 2004 1:31 am Post subject: TidThreadComponent and Free |
|
|
Hi, i'm using TidThreadComponent as an internal field of my class.
TMyJob = class(TObject)
FThread: TidThreadComponent;
FClient: TidTcpClient;
...
...
end;
when i'm using this class like this :
var
MyJob: TMyJob;
begin
MyJob := TMyJob.Create();
try
CeoJob.StartJob;
// Sleep(5000)
finally
CeoJob.Free;
end;
end;
it calls TMyJob.Free before FThread finish it's work. When I give
enough time to finish it's work with adding Sleep(5000) line,
everything is ok. It's not a good way i know that so i wants to know
what is the solution of this problem.
- Jacky
|
|
| Back to top |
|
 |
Jacky Guest
|
Posted: Thu Apr 22, 2004 12:23 pm Post subject: Re: TidThreadComponent and Free |
|
|
I typed wrong. CeoJob should be MyJob. Sorry about it
Jacky wrote:
| Quote: | Hi, i'm using TidThreadComponent as an internal field of my class.
TMyJob = class(TObject)
FThread: TidThreadComponent;
FClient: TidTcpClient;
...
...
end;
when i'm using this class like this :
var
MyJob: TMyJob;
begin
MyJob := TMyJob.Create();
try
CeoJob.StartJob;
// Sleep(5000)
finally
CeoJob.Free;
end;
end;
it calls TMyJob.Free before FThread finish it's work. When I give
enough time to finish it's work with adding Sleep(5000) line,
everything is ok. It's not a good way i know that so i wants to know
what is the solution of this problem.
- Jacky
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Apr 22, 2004 8:14 pm Post subject: Re: TidThreadComponent and Free |
|
|
"Jacky" <noname (AT) noname (DOT) com> wrote
| Quote: | it calls TMyJob.Free before FThread finish it's work. When I
give enough time to finish it's work with adding Sleep(5000) line,
everything is ok. It's not a good way i know that so i wants to
know what is the solution of this problem.
|
Have you considered simply adding a destructor to TMyJob that stops the
thread and actually waits for it to fully terminate before then freeing it?
Gambit
|
|
| Back to top |
|
 |
|