Delphi app not closing properly

I am the developer of a widely distributed application written in Delphi 5. Recently there have been some reports from users that when closing the app, it remains in the taskbar and can only be terminated using Task Manager. I have occasionally seen this myself and have also seen an instance where it wasn't in the taskbar but the process was still running, but I haven't found any specific action that causes it. This has only been happening for the last few months so I assume it has something to do with a 
recent code change, but I don't know exactly what causes this and have no idea how to search for the possible cause. I would appreciate any hints on what causes this and how to find the part of the code that needs fixing.
0
Glenn
4/25/2009 5:54:36 PM
embarcadero.delphi.rtl 934 articles. 0 followers. Follow

9 Replies
844 Views

Similar Articles

[PageSpeed] 26

On Sat, 25 Apr 2009 10:54:36 -0700, Glenn Alcott wrote:

> I am the developer of a widely distributed application written in Delphi 5. Recently there have been some reports from users that when closing the app, it remains in the taskbar and can only be terminated using Task Manager. I have occasionally seen this myself and have also seen an instance where it wasn't in the taskbar but the process was still running, but I haven't found any specific action that causes it. This has only been happening for the last few months so I assume it has something to do with 
a 
> recent code change, but I don't know exactly what causes this and have no idea how to search for the possible cause. I would appreciate any hints on what causes this and how to find the part of the code that needs fixing.

I ran into the same thing, and tracked down the source with some help from
the forums. You'll find all the details here:

http://tinyurl.com/dbhr78

The offending HP app affects about 2% of my users.

HTH, but your problem might have a quite different cause.

-- 
Pete
0
Peter
4/25/2009 7:27:50 PM
> {quote:title=Peter Martin wrote:}{quote}
> On Sat, 25 Apr 2009 10:54:36 -0700, Glenn Alcott wrote:
> 
> > I am the developer of a widely distributed application written in Delphi 5. Recently there have been some reports from users that when closing the app, it remains in the taskbar and can only be terminated using Task Manager. I have occasionally seen this myself and have also seen an instance where it wasn't in the taskbar but the process was still running, but I haven't found any specific action that causes it. This has only been happening for the last few months so I assume it has something to do wit
h a 
> > recent code change, but I don't know exactly what causes this and have no idea how to search for the possible cause. I would appreciate any hints on what causes this and how to find the part of the code that needs fixing.
> 
> I ran into the same thing, and tracked down the source with some help from
> the forums. You'll find all the details here:
> 
> http://tinyurl.com/dbhr78
> 
> The offending HP app affects about 2% of my users.
> 
> HTH, but your problem might have a quite different cause.
> 
> -- 
> Pete

Thanks for the tip but I doubt this has anything to do with it, since I don't have any HP app on my system. Also, the fact that it's only happened recently (and I've been working on this app for 8 years) leads me to believe it's something recent in my code.

Are there any debugging tools out there that can solve problems like this (like the old BoundsChecker)?

Glenn
0
Glenn
4/25/2009 7:55:40 PM
Glenn Alcott wrote:
> I am the developer of a widely distributed application written in Delphi 5. Recently there have been some reports from users that when closing the app, it remains in the taskbar and can only be terminated using Task Manager. I have occasionally seen this myself and have also seen an instance where it wasn't in the taskbar but the process was still running, but I haven't found any specific action that causes it. This has only been happening for the last few months so I assume it has something to do with 
a 
> recent code change, but I don't know exactly what causes this and have no idea how to search for the possible cause. I would appreciate any hints on what causes this and how to find the part of the code that needs fixing.

Most often, this is because a Thread is in "suspended" mode and "Free" 
is being called on it. But Free uses WaitFor which does not yield enough 
time for the thread to start and be terminated.
Or, you have a TThread that does not check its Terminated property often 
enough to stop itself fast when it is being asked to do so.
0
Olivier
4/25/2009 9:23:39 PM
> {quote:title=Olivier Sannier wrote:}{quote}
> Glenn Alcott wrote:
> > I am the developer of a widely distributed application written in Delphi 5. Recently there have been some reports from users that when closing the app, it remains in the taskbar and can only be terminated using Task Manager. I have occasionally seen this myself and have also seen an instance where it wasn't in the taskbar but the process was still running, but I haven't found any specific action that causes it. This has only been happening for the last few months so I assume it has something to do wit
h a 
> > recent code change, but I don't know exactly what causes this and have no idea how to search for the possible cause. I would appreciate any hints on what causes this and how to find the part of the code that needs fixing.
> 
> Most often, this is because a Thread is in "suspended" mode and "Free" 
> is being called on it. But Free uses WaitFor which does not yield enough 
> time for the thread to start and be terminated.
> Or, you have a TThread that does not check its Terminated property often 
> enough to stop itself fast when it is being asked to do so.

Sorry, but this app does not use any threads.
0
Glenn
4/25/2009 9:26:36 PM
Glenn Alcott a écrit :
> Also, the fact that it's only happened recently (and I've been working on this app for 8 years) leads me to believe it's something recent in my code.

Not necessary of your code only...
A long time ago, I noticed some changes in the comportment of one of my tools 
that was due from a windows update.
:-(

Pascal
0
Pascal
4/25/2009 9:49:23 PM
Glenn Alcott wrote:

> > Most often, this is because a Thread is in "suspended" mode and
> > "Free" is being called on it. But Free uses WaitFor which does not
> > yield enough time for the thread to start and be terminated.
> > Or, you have a TThread that does not check its Terminated property
> > often enough to stop itself fast when it is being asked to do so.
> 
> Sorry, but this app does not use any threads.

Oh, that is what you think, but it may not reflect reality <g>.  You
may be using some 3rd-party code that internally uses threads. Did you
move to a new version of one of the 3rd-party things you use?

Unfortunately such problems are very hard to isolate if you cannot
reproduce them at will. Since you say that usually the taskbar button
remains (but I assume the forms are not visible anymore) the problem
seems to strike before the VCL has finished destroying the Application
object. So it may be connected to the destruction of a component you
use on any of the forms or data modules that are still around when the
application is closed.

You have not told us anything about what your application does, so it's
a bit hard to give any recommendations of where to look specifically.
Anyway, if you are using database access, don't rely on the database
connection being closed correctly when the datamodule or form
containing the access components is destroyed. Close the datasets and
connection in code when the app goes down (e.g. from the main forms
OnClose event). This way you can make sure everything is closed in the
correct sequence. The same applies to other connections to the world
outside your app, e.g. any TCP/IP communication channels, connection to
mail servers, open files, and so on. Usually these are all dealt with
OK by the standard cleanup done when the components you use are
destroyed, but sometimes there are interdependencies that require
things to be cleaned up in a particular sequence to avoid problems. So
it's better to be explicit in this area in my experience.


-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
0
Peter
4/26/2009 7:43:02 AM
> {quote:title=Peter Below wrote:}{quote}
> Glenn Alcott wrote:
> 
> > > Most often, this is because a Thread is in "suspended" mode and
> > > "Free" is being called on it. But Free uses WaitFor which does not
> > > yield enough time for the thread to start and be terminated.
> > > Or, you have a TThread that does not check its Terminated property
> > > often enough to stop itself fast when it is being asked to do so.
> > 
> > Sorry, but this app does not use any threads.
> 
> Oh, that is what you think, but it may not reflect reality <g>.  You
> may be using some 3rd-party code that internally uses threads. Did you
> move to a new version of one of the 3rd-party things you use?
> 
> Unfortunately such problems are very hard to isolate if you cannot
> reproduce them at will. Since you say that usually the taskbar button
> remains (but I assume the forms are not visible anymore) the problem
> seems to strike before the VCL has finished destroying the Application
> object. So it may be connected to the destruction of a component you
> use on any of the forms or data modules that are still around when the
> application is closed.
> 
> You have not told us anything about what your application does, so it's
> a bit hard to give any recommendations of where to look specifically.
> Anyway, if you are using database access, don't rely on the database
> connection being closed correctly when the datamodule or form
> containing the access components is destroyed. Close the datasets and
> connection in code when the app goes down (e.g. from the main forms
> OnClose event). This way you can make sure everything is closed in the
> correct sequence. The same applies to other connections to the world
> outside your app, e.g. any TCP/IP communication channels, connection to
> mail servers, open files, and so on. Usually these are all dealt with
> OK by the standard cleanup done when the components you use are
> destroyed, but sometimes there are interdependencies that require
> things to be cleaned up in a particular sequence to avoid problems. So
> it's better to be explicit in this area in my experience.
> 
> 
> -- 
> Peter Below (TeamB)  
> Don't be a vampire (http://slash7.com/pages/vampires), 
> use the newsgroup archives :
> http://www.tamaracka.com/search.htm
> http://groups.google.com

Peter,

Thanks for your response and for all your contributions to the Delphi forums over the years, many of which I have found invaluable.

Unfortunately, in this case you are only causing me further frustration <g> by telling me how difficult these things are to debug, which of course I already know!! But I guess I can't expect miracles.

This is a database application using Advantage Database. It doesn't do any TCP/IP, mail server connection, etc. There's been no change in the way it handles the database connection or opening/closing of datasets. I am going to have do a careful inspection of all my recent changes to see if I can find anything; at this point I don't know what else to do. Actually I'm not convinced that it's a serious problem because it's only been reported a few times and I have a very hard time duplicating it, but my clie
nt (the vendor of the app) is the one who gets to hear from the users and it's frustrating him so he wants to pursue it to some extent.

Glenn
0
Glenn
4/26/2009 5:00:55 PM
> problem because it's only been reported a few times and I have a very
> hard time duplicating it, but my clie nt (the vendor of the app) is
> the one who gets to hear from the users and it's frustrating him so
> he wants to pursue it to some extent.

I can tell you have I found the HP problem with the shell.  

1) I had to duplicate it but since you are seeing it once in a while
you have a chance.
2) Install Process Explorer (now maintained by M$ but still free)
3) When it hangs and won't close run process Explorer
4) Look at all the handles and threads still alive in your app with PE
5) Use some physic debugging and start killing handles that seem like
they may have enough "power" that they may be hanging the app.  Hint:
Things like registry handles would not likely be "powerful" enough to
stop you app from closing.
6) When you hit the right one, i.e. the app suddenly finishes closing
after killing a handle, it will give you a better clue where the issue
may be.

Good luck,
Jim
-- 
www.mustangpeak.net
0
Jim
4/27/2009 5:30:33 PM
Glenn Alcott wrote:
> I am the developer of a widely distributed application written in Delphi 5. Recently there have been some reports from users that when closing the app, it remains in the taskbar and can only be terminated using Task Manager. I have occasionally seen this myself and have also seen an instance where it wasn't in the taskbar but the process was still running, but I haven't found any specific action that causes it. This has only been happening for the last few months so I assume it has something to do with 
a 
> recent code change, but I don't know exactly what causes this and have no idea how to search for the possible cause. I would appreciate any hints on what causes this and how to find the part of the code that needs fixing.

I have had this happen because of a deadlock on a TCriticalSection, or a 
background thread that never terminates, and I have also had this happen
when you have a low level USB problem with a device driver such as a 
serial port.  Even some Win32 APIs like CloseHandle could freeze 
forever.  I have also seen problems caused by mapped drives that are not
available on the network and network printers installed that are no 
longer visible on the network. And then there's anti-virus tools,
pre-loaded crapware (like the HP stuff someone mentioned).  You have
no shortage of options.  Pick three. :-)

If I'm in doubt, I would add some OutputDebugString messages, and use an 
ODS viewer to see the shutdown progress, just like you could see them if 
you were running in the debugger.


W
0
Warren
6/8/2009 7:58:24 PM
Reply:

Similar Artilces:

Delphi app not always closing properly
I am the developer of a widely distributed application written in Delphi 5. Recently there have been some reports from users that when closing the app, it remains in the taskbar and can only be terminated using Task Manager. I have occasionally seen this myself and have also seen an instance where it wasn't in the taskbar but the process was still running, but I haven't found any specific action that causes it. This has only been happening for the last few months so I assume it has something to do with a recent code change, but I don't know exactly what causes this and have ...

Delphi 2007 RTL in Delphi 7
I read somewhere that it is possible to use Delphi 2007's (or for that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the source of RTL. Is this really possible? What are the benefits that we can derive using a higher version's RTL? TIA Yogi Yang Yogi Yang wrote: > I read somewhere that it is possible to use Delphi 2007's (or for > that matter Delphi 2006's) RTL in Delphi 7 by just recompiling the > source of RTL. If it actually compiles in Delphi 7, I guess it would be possible. OTOH, if one has Delphi 2007 already, I don't s...

delphi 2010 memory not released when closing delphi project
each time im runing delphi 2010 the memory that was used was not release after closing a project and the memory don't stop to grow and the browsing for file becoming slow any idea ? Thanks Pierre Auger wrote: > each time im runing delphi 2010 the memory that was used was not > release after closing a project and the memory don't stop to grow and > the browsing for file becoming slow > > any idea ? You are using some 3rd-party components that do not properly release memory in their design-time packages would be my guess. A design-time package stays l...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

problem delphi 2010 apps with a delphi 5 pro Pchar
Hallo I build on till now alle tools and programas with delphi 5 pro now i have delphi 2010 want don't want rewite alle my DLL Tools Like The tool i made for making PDF In case of This DLL i can't becose the vcl i use in delphi 5 will not work in delphi 2010 *This call in apps* {code} Function GenratePDF(Settings:Pchar):Boolean; stdcall external 'GUPPDF2.dll'; {code} *In delphi 5 DLL* {code} Function GenratePDF(Settings:Pchar):Boolean; stdcall; {code} if call the function i get a "Access violation" i think that the settings parameter empty is...

How to build enterprise-grade Delphi app
Hi It would be nice to build enterprise-grade appl with Delphi, but are the options or third party software (like in J2EE) to do this? e.g. 1) there is J2EE middleware for hosting components - developer is not required to handle all the issues that are connected with session handling and different contexts in which the components can be stored (like application, session, request context, etc.). I understand that some of this can be done in DataSnap or in Web Services (can be even PHP, Java or .NET) and Delphi client - but in both cases there are some drawbacks: - for DataSnap - much shou...

Delphi 2010: AV when switching from Default to debug layout and when closing Delphi
Hello, I experience strange AVs in rtl140.bpl when switching from the Default to the Debug Layout (e.g. when starting the application) or when closing Delphi 2010. I have a bunch of Addins (Modelmaker Code Explorer, EurekaLog, DDevExtensions, JCL, etc...), components installed. Any ideas/tools to possibly track down where the culprit is? Possibly simply an addin in combination with docked windows etc. Thanks, Thomas > {quote:title=Thomas Steinmaurer wrote:}{quote} > I experience strange AVs in rtl140.bpl when switching from the Default > to the Debug Layout (...

Convert Delphi 5 ADO App to Delphi 2007 ADO.NET
I have an appliction tha that is writen in Delphi 5 with ADOConnetion, ADOTable, and ADOQuery components. I need to upgrade to Delphi 2007 and use ADO.NET. I have the program building in with Delphi 2007. Is there anything I need to do to convert the ADO to ADO.NET? > I need to upgrade to Delphi 2007 and use ADO.NET. Why ? -- With best regards, Dmitry Arefiev AnyDAC (www.anydac.com) - Oracle, MS SQL Server, IBM DB2, MySQL, Firebird, Interbase, PostgreSQL, Sybase ASA, SQLite, MS Access, DBX, ODBC, InMem - universal high-speed native data access engine Reasons for ...

How to fully close a Delphi-XE5 Android App?
This has been asked before but not fully answered. I want to exit an app for two reasons. 1. on startup if problems with the data files and (I'd also like to know to handle this case on IOS too!) 2. from a back-button press Other answere here and elsewhere got answers of using: SharedActivity.Finish; or MainActivity.Finish; Both appear to close the window but neither exit the application as in debug mode the program does not end in Delphi and the application is still running on the device itself. The apps seem to eventually go away when in that state, but if you tr...

Close Delphi XE4 Metro App With Touch
When you create a Metro application with Delphi XE4 it does not act like a normal Metro application because you can *not close the application with a finger swipe from the top of the screen to the bottom of the screen*. All of the Metro apps I have that came with windows actually close with touch this way. You are returned to the Start screen... then if you go to the desktop the app is no longer running. When you close a Delphi Metro application with a swipe from the top of the screen to the bottom of the screen it returns you to the Start screen. If you then go to the desktop.. the applicat...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Delphi 2007 to Delphi 7
I've written a class in Delphi 2007 that is not supported in Delphi 7. What would be the best way to achive what I've done in Delphi 2007 in Delphi 7? Thanks, Tom type BondConstants = class { Bond Types } type BondType = record const TREASURY = 3; AGENCY = 0; CORP = 1; MUNI = 2; SBA = 5; MBS = 4; CMO = 6; end; { Day Count Methods } type DayCount = record const ACTUAL_360 = 2; ACTUAL_365 = 1; ACTUAL_ACTUAL = 1; d30_360 = 0; ...

Delphi 7 to Delphi XE
Have been using Delphi 7 for many moons ( have got later versions but never upgraded to ) My first problem is: Component Palette. in XE it is a small toolbar docked in top right in Delphi 7 it gives a large view of all the components. I am struggling to be able to cope/access my components.in Delphi XE. Can I make the component pallette tool bar the same size as Delphi 7, or is there a fast way to view/choose all available components in XE, that I have not spotted yet? Kind Regards, Robert. Hi, What I know is that in Delphi 2010 and XE you can choose between t...

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

Web resources about - Delphi app not closing properly - embarcadero.delphi.rtl

Statement of Disaffiliation from the GUU regarding failure to properly address Misogynistic behaviour ...
Glasgow Uni Coalition of Resistance hat eine Notiz mit dem Titel Statement of Disaffiliation from the GUU regarding failure to properly address ...


How to use a Ketchup Cup Properly - YouTube
Ever carry over 8 cups full of ketchup back to your table, try to dunk more than one fry at a time, and think to yourself, "This doesn't seem ...

University reforms haven't been explained properly, says Sydney Uni's Michael Spence
... of the proposal to uncap university fees has taken an apparent swipe at the government's sales job saying the case for change hasn't been properly ...

Canada crash train brakes not set properly
A lone engineer failed to set brakes properly on a train that derailed and exploded in a small Canadian town, killing at least 15 people, the ...

How to pour champagne properly
French scientists say they have settled the question of how best to pour champagne.

Queensland Health probes: 50,000 x-rays not properly checked
An investigation is underway after revelations almost 50,000 x-rays taken at public hospitals on the Gold Coast have not been properly checked. ...

Vaccination: nearly one in 10 Brunswick five-year-olds not properly immunised
Brunswick's &quot;alternative&quot; trends have been blamed for nearly one in 10 of its five-year-olds not being properly immunised.

Fracking's effect on water not properly monitored, report finds
A new report commissioned by Environment Canada says there's little information about the effects of shale gas development on the environment. ...

'We want to know how to love them properly,' veteran's spouse says
A day after confronting the Veterans Affairs minister over lack of support for veterans’ caregivers, the wife of a former Canadian Forces sergeant ...

Resources last updated: 1/13/2016 9:15:57 PM