Link to home
Start Free TrialLog in
Avatar of tkamrath
tkamrath

asked on

VB6 Debug "END" button vs. App termination

I am using VB6 as my test environment for an ATL COM activeX object in a dll.  The COM activeX object accesses the data in the VB6 test app.  When I run the test app as an .exe it works fine.  But when I run the app from the VB6 IDE in debug mode and terminate it with the debug "END" button in the toolbar, VB6 terminates without any warning or error.  And terminating debug from within the app still works.  I need to know exactly what each of these two debug termination methods do behind the scenes and what the differences are between them.  A sequence of events upon pressing the END button would be nice, a step-by-step description of what happens.  Do you know this or know where I can find a description of this sort?  Thanks.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

END when using unsafe subclassing can have that effect....
Avatar of tkamrath
tkamrath

ASKER

No subclassing being done.  Do you know what the END button does and what the diff is between it and ending the app from within (i.e. close button on the app main form)?
Pressing the End button is similar to calling the End statement.  Both bring your execution to an immediate halt, and don't allow your process to clean up after itself.  

For normal termination, you finish processing, unload forms, close connections and release resources.  If you start from Sub Main, then when that sub finishes executing, your program stops.  If you start from a form, then when all forms are unloaded, your program will stop.  

When you hit the end button, or use the End statement, then the environment attempts as clean an exit as possible, without continuing to run your code.  Resources opened with API methods are least likely to be cleaned up, so depending on your usage, you may leave open files, unreleased GDC resources etc and other Very Bad Things.

What's causing your IDE to crash, I can't really speculate on, except to say that I've occasionally seen things like this.  You might check the event log to see if anything is being recorded there.


END kills the process directly, in an unclean why.
the close button will request the Form_QueryUnload event, and if the cancel parameter is not set the true, it will call the Form_Unload event, and finally release all the resources.
My ActiveX object creates a thread.  And I have a mechanism to terminate the thread before the app is closed.  But this does not help in the case of an END.  So there is no mechanism to force a cleanup when VB ends a debug session?  A way to force a form deactivate or unload or something?
do not use END as such.
if you have a method to close the thread(s), use that before using END.
>So there is no mechanism to force a cleanup when VB ends a debug session?

Other than by normally terminating your program by the methods suggested above, no there really isn't any way to do that when clicking the "End" button.
So this problem exists for anyone who does multi-threading in VB6?  I don't see how you can get around it.  If the application gets started and has generated other threads there is no way of closing them cleanly when a debug session is closed, right?  This may not be a problem for threads that do not share any data, but if the threads access any part of the main thread then this will happen. BUMMER!
ASKER CERTIFIED SOLUTION
Avatar of PaulHews
PaulHews
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial