|
I'm probably going to be shot for giving away
secrets, but hey...
A can be solved easily if you get your form
to create a Windows event (using the API call CreateEvent) and pass this as a
parameter to your thread's constructor. You thread can check this event
periodically (by waiting on it for no time) and then commit suicide if the event
is set. This is a very safe way of ensuring that you are not referencing a
thread that has already died.
Pass the owner as a parameter to the thread
constructor. This should allow you to set fOwner.fTherad := nil when the
thread terminates.
Set FreeOnTerminate to false in your
constructor.
Set FreeOnTerminate to true in the execute method
when the thread has finished and after you have set fOwner.fThread to
nil.
The form that started the thread can then (in its
destructor) say:
SetEvent(MyThreadDie);
while assigned(fThread) do;
If the variable holding MyThreadDie is the event
that you created when you instatiated the thread then by setting the event you
can expect the thread to suicide. You need to wait for it, not by
MyThread.WaitFor, but by waiting until it has set its owner's reference to
nil. After having done that, it should free itself.
Trevor
|
- [DUG]: Threads again Ross Levis
- Re: [DUG]: Threads again Trevor Jones
- Re: [DUG]: Threads again Ross Levis
- RE: [DUG]: Threads again David Brennan
- [DUG]: Another MS/Borland stuffup Trevor Jones
- [DUG]: Another MS/Borland stuffup Rohit Gupta
- [DUG]: Delphi 7 - Designeditors Rohit Gupta
- Re: [DUG]: Delphi 7 - Designeditors Neven MacEwan
- [DUG]: dcp inside bpl Rohit Gupta
- RE: [DUG]: Threads again Stacey Verner
- Re: [DUG]: Threads again Ross Levis
