Yeah probably because you have FreeOnTerminate set to true. I would do as Allan suggested below and set FreeOnTerminate to false Then free the thread yourself
aThread.Terminate; aThread.WaitFor; aThread.Free; you in which case you should reference any > -----Original Message----- > From: Phil Middlemiss [mailto:[EMAIL PROTECTED] > Sent: Wednesday, 25 August 2004 10:50 a.m. > To: NZ Borland Developers Group - Delphi List > Subject: Re: [DUG] Threads > > > Now I am getting an error during the call to WaitFor - > "Project .... raised > exception class EOSError with message 'System Error. Code:6. > The handle is > invalid'....'. I copied over the classes.pas unit into my > path and traced > through - the error occurs in the TThread.Destroy method > where it calls > CloseHandle on line 9066 (Delphi 6). I'm not calling any > other methods on > the thread - just creating it then calling terminate and waitfor. > > Any ideas? > > Cheers, > Phil. > ----- Original Message ----- > From: "Allan, Samuel" <[EMAIL PROTECTED]> > To: "NZ Borland Developers Group - Delphi List" <[EMAIL PROTECTED]> > Sent: Wednesday, August 25, 2004 9:40 AM > Subject: RE: [DUG] Threads > > > > If your containing object "frees [the thread] in it's > destructor", then > > you are taking responsibilty for the destruction of the > thread. Thus you > > should set FreeOnTerminate to False. > > > > If you want FreeOnTerminate to be True, then you should > only terminate > > the thread, and not free it. Of course, if the thread > accesses objects > > that die along with the container object then you will get access > > violations. > > > > To ensure that you free the thread only after it has completed > > execution, you could use: > > > > aThread.Create(Suspended); > > aThread.FreeOnTerminate := False; > > aThread.Resume; > > ... > > aThread.Terminate; > > aThread.WaitFor; //Or whatever it is.. > > aThread.Free; > > > > This will ensure that the thread completes execution before > it is freed. > > The thread that is executing the above code will block > until the target > > thread ceases execution. > > > > > > > > -----Original Message----- > > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] > > On Behalf Of Phil Middlemiss > > Sent: Wednesday, August 25 2004 9:23 a.m. > > To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List > > Subject: Re: [DUG] Threads > > > > > > I've played with setting FreeOnTerminate to False, but in > that case I > > have > > to manually call Terminate and also manually Free the > object - it's a > > reusable component and I don't want any other components to > have to do > > anything special other than Terminate the thread. > > > > Phil. > > > > ----- Original Message ----- > > From: "Sandeep Chandra" <[EMAIL PROTECTED]> > > To: "NZ Borland Developers Group - Delphi List" > <[EMAIL PROTECTED]> > > Sent: Wednesday, August 25, 2004 8:51 AM > > Subject: Re: [DUG] Threads > > > > > > > Hi Phil > > > > > > Try setting FreeOnTerminate to false if you want to free > threadobject > > > yourself. > > > > > > Regards > > > > > > Sandeep > > > > > > >Hi all, > > > > > > > >I have a thread object that, for some reason, the > destructor is being > > called > > > >twice. I've stripped the app down to a fairly simple > shell around the > > thread > > > >and all I am doing is creating the object that holds > onto the thread, > > and > > > >then freeing it. The containing object creates the thread in it's > > > >consctructor and frees it in its destructor. Any one know what is > > causing > > > >this? > > > > > > > >Cheers, > > > >Phil. > > > > > > > >_______________________________________________ > > > >Delphi mailing list > > > >[EMAIL PROTECTED] > > > >http://ns3.123.co.nz/mailman/listinfo/delphi > > > > > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > > Delphi mailing list > > > [EMAIL PROTECTED] > > > http://ns3.123.co.nz/mailman/listinfo/delphi > > > > _______________________________________________ > > Delphi mailing list > > [EMAIL PROTECTED] > > http://ns3.123.co.nz/mailman/listinfo/delphi > > > > _______________________________________________ > > Delphi mailing list > > [EMAIL PROTECTED] > > http://ns3.123.co.nz/mailman/listinfo/delphi > > > > _______________________________________________ > Delphi mailing list > [EMAIL PROTECTED] > http://ns3.123.co.nz/mailman/listinfo/delphi > _______________________________________________ Delphi mailing list [EMAIL PROTECTED] http://ns3.123.co.nz/mailman/listinfo/delphi
