🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5626

Re: TThread & CloseHandle

#5626
From: Tassilo J. Klein
Date: Fri, 05 Aug 2005 14:00
123 lines
3967 bytes
It seems to be a problem of the IDE. When I run my software outside of 
the IDE there is no problem. The TThread won't be killed and it works 
the way it is supposed to. How is that possible???

  -Tassilo
> Hi Gambit,
> 
> Thanks for trying to help.
> 
> 
> Remy Lebeau (TeamB) wrote:
> 
>> "Tassilo J. Klein" <nospamTJKlein@web.de> wrote in message
>> news:dctdlr$6gr$02$1@news.t-online.com...
>>
>>
>>> Invocation of CloseHandle function out of any reason then calls the
>>> destructor of the calling TThread ~DownloadThread()
>>
>>
>>
>> The only way that could be happening is if CloseHandle() is throwing an
>> exception that is terminating the thread, and if you have the thread 
>> set to
>> FreeOnTerminate=true (or external code that is 'delete'ing the thread 
>> after
>> a call to WaitFor()).
>>
>>
> 
> Yes, is FreeOnTerminate = true;
> 
> 
>>> although CloseHandle is encapsulated by try/catch blocks.
>>
>>
>>
>> That does not necessarily mean that the try..catch will actually catch an
>> exception.  It depends on what your catch block is actually looking 
>> for, and
>> what kind of exception, if any, is actualy being thrown.  What does the
>> actual code look like?
> 
> 
> Here is a part of the code of the TThread. But everything critical is 
> encapsulated with try and catch(...). I don't understand it....
> 
> void __fastcall DownloadThread::Execute()
> {
> 
>     while( Terminated == false)
>     {
> 
>         try
>         {    // opening the port to the device
> 
>         if ( device->startDevice() != DEVICE_OK )
>                         throw(TRANSFER_ERROR);
> 
>         // download data from the device
> 
>         if ( device->downloadSpectrum() != DEVICE_OK)
>                         throw(TRANSFER_ERROR);
>        
>         .....
>     }
>     catch(...)
>     {
>         ...
>         // close the port
>         device->stopDevice();
>         ...
>     }
>     WaitForSingleObject(event, wait );
> }
> 
> // stop the device, close the port
> virtual void TMDU::stopDevice()
>     {
>         closePort();
>         monitor->Release();
>     };
> 
> 
> void TMDU::closePort()
> {
>     //closing the COM port
>     try
>     {
>     // write a byte to the device to finish communication
>     exitPort();
> 
>     flushPort();
> 
>      if ( hCom > 0 )
>     {
>      // clear data in the puffer
>       PurgeComm(hCom, PURGE_TXABORT | PURGE_RXABORT );
> 
>       // free the handle
>      CloseHandle( hCom ); }              <-------- from here the 
> debugger steps to the destructor of the download thread
> 
>     hCom = NULL;
>     }
>     }
>     catch(...)
>     {
>      .....
>     }
> }
> 
> 
> Any clue?
> 
> Regards,
>  -Tassilo
> 
>>
>>
>> Gambit
>>
>>
Technical Details
Message-ID: <dcvrel$50c$00$1@news.t-online.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
References: <dctdlr$6gr$02$1@news.t-online.com> <42f24cfe$1@newsgroups.borland.com> <dcviup$pn$04$1@news.t-online.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,185dcaeb91f025d5
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!newsmm00.sul.t-online.de!t-online.de!news.t-online.com!not-for-mail
From: "Tassilo J. Klein" <nospamTJKlein@web.de>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: TThread & CloseHandle
Date: Fri, 05 Aug 2005 16:00:29 +0200
Organization: T-Online
Lines: 123
Message-ID: <dcvrel$50c$00$1@news.t-online.com>
References: <dctdlr$6gr$02$1@news.t-online.com> <42f24cfe$1@newsgroups.borland.com> <dcviup$pn$04$1@news.t-online.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.t-online.com 1123250454 00 5132 VHivJGtl29o503B 050805 14:00:54
X-Complaints-To: usenet-abuse@t-online.de
X-ID: JOo18BZGZeAkWrfYu1hBQ2qCGxWAHKJIF2oVclotbw-DpdqajlSjwr
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: en-us, en
In-Reply-To: <dcviup$pn$04$1@news.t-online.com>