Do not use on any
shared computer
July 24, 2008 07:47pm pdt
null
[x]
Attachment Details

2.5 second "pause" between when code exits and command line comes back (ThreadExit)

Tags: C
I have a Win32 command line application that uses ODBC calls to access any database.  Everything seems to be working great, except for a minor performance issue that we are now battling.  At the end of the code, as the application is termination, we are seeing a "pause" that can run as long as 2.5 seconds (or more).  

This is not in my code, but rather is AFTER my code exits.  The end of the application looks like this:
      if(DisplayTimes)
            PrintTime("Tearing Down SQL Environment");
      TearDownSQLEnvironment();
      if(DisplayTimes)
            PrintTime("Complete!");
      exit(ReturnStatus);
}

When run, I get a list of timestamps including the following:

18:29:43.650: Finished Data Read
18:29:43.650: Free Statement Handle
18:29:43.650: Disconnect from Database
18:29:43.728: Tearing Down SQL Environment
18:29:43.728: Complete!

As you can see, the call to disconnect from the database takes some time, but tearing down the environment takes almost no time at all.  The problem, though, is that the program is exiting, but control is not returned to the command line for some time thereafter.  The code snippet shows a Process Monitor trace that shows that the Thread Exit call is occurring at 18:29:43.719 (actually a bit BEFORE the program actually finishes, but this could be a timer issue).  In any event, nothing happens for the next 2.5 seconds and we sit there waiting for the command prompt to come back.  Even checking through the intervening calls with ProcMon, I don't see anything other than the typical "idle chatter" of AV and other agents.  (No, AV is not the issue, as I can duplicate the problem on other systems with no AV code.)

The application I am using is called SQLExec, and is also available for download from www.goldstarsoftware.com/tools.asp.  You can test it yourself to any ODBC database by issuing a command like this:
    SQLEXEC <DSNName> "SELECT TOP 1 * FROM TableName" /DT

The app is fast, but the delay FOLLOWING the app is positively maddening!  Help!

I've surmised that this is unloading of DLL's related to ODBC and the database, but I have not found a way to confirm this as of yet.  
1:
2:
3:
4:
5:
6:
7:
8:
17145	18:29:43.7198046	sqlexec.exe	4640	Thread Exit		SUCCESS	User Time: 0.0000000, Kernel Time: 0.0000000
19361	18:29:46.2529335	sqlexec.exe	4640	RegOpenKey	HKLM\Software\Microsoft\Windows NT\CurrentVersion\GRE_Initialize	SUCCESS	Desired Access: Read
19362	18:29:46.2529836	sqlexec.exe	4640	RegQueryValue	HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\GRE_Initialize\DisableMetaFiles	NAME NOT FOUND	Length: 20
19363	18:29:46.2530469	sqlexec.exe	4640	RegCloseKey	HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\GRE_Initialize	SUCCESS	
19365	18:29:46.2531342	sqlexec.exe	4640	Thread Exit		SUCCESS	User Time: 0.0312500, Kernel Time: 0.2031250
19374	18:29:46.2542871	sqlexec.exe	4640	Process Exit		SUCCESS	Exit Status: 0, User Time: 0.0468750, Kernel Time: 0.1562500
19375	18:29:46.2545963	sqlexec.exe	4640	CloseFile	C:\Develop\Win32\SQLExec\Release	SUCCESS	
19377	18:29:46.2548343	sqlexec.exe	4640	CloseFile	C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03	SUCCESS
Start your free trial to view this solution
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Question Stats
Zone: Programming
Question Asked By: BillBach
Solution Provided By: Infinity08
Participating Experts: 5
Solution Grade: A
Views: 13
Translate:
Loading Advertisement...
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Accepted Solution by Infinity08

Rank: Sage

Accepted Solution by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by evilrix

Rank: Guru

Expert Comment by evilrix:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by evilrix

Rank: Guru

Expert Comment by evilrix:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by evilrix

Rank: Guru

Expert Comment by evilrix:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by evilrix

Rank: Guru

Assisted Solution by evilrix:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by PaulCaswell

Rank: Guru

Assisted Solution by PaulCaswell:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by PaulCaswell

Rank: Guru

Expert Comment by PaulCaswell:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Assisted Solution by wayside
Assisted Solution by wayside:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by Infinity08

Rank: Sage

Expert Comment by Infinity08:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by wayside
Expert Comment by wayside:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Expert Comment by DanRollins

Rank: Guru

Expert Comment by DanRollins:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
[+][-]Author Comment by BillBach
Author Comment by BillBach:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080723-EE-VQP-34 / EE_QW_2_20070628