🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TThread & CloseHandle

#5625
From: Tassilo J. Klein
Date: Fri, 05 Aug 2005 11:35
111 lines
3443 bytes
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: <dcviup$pn$04$1@news.t-online.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!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>

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!news3.google.com!news.glorb.com!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 13:35:29 +0200
Organization: T-Online
Lines: 111
Message-ID: <dcviup$pn$04$1@news.t-online.com>
References: <dctdlr$6gr$02$1@news.t-online.com> <42f24cfe$1@newsgroups.borland.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 1123241753 04 823 JlgvJ9xOvuDGSs+I 050805 11:35:53
X-Complaints-To: usenet-abuse@t-online.de
X-ID: GWk4YrZLrecCAlSo3RMIVcvX03V1db5c1C8DTzmZ-AoRTO0waOHeQu
User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)
X-Accept-Language: en-us, en
In-Reply-To: <42f24cfe$1@newsgroups.borland.com>