-
August 25th, 2002, 10:34 PM
#1
vb6 slow shutdown
I have written a rather large program in vb6 that takes forever to shutdown...I'm mean on the order of minutes! I have tried everything I know to make it shutdown faster, including unloading all the forms etc. I ultimately use the "End" statement to do it, but it still takes too long. A previous version of this same program in vb3 shutdown "instantaneously". ?? Can anyone enlighten me on this?
I can shut this program down and it may remain in the running programs list that you get with "ctrl-alt-del" for 2 or 3 minutes or more.
I would appreciate any help I can get on this.
Thanks,
JB
-
August 26th, 2002, 03:18 AM
#2
Put some MsgBox prompts in the various events that fire on shutdown. That may help you narrow down a bit where the lag is occurring.
Is there code that's doing anything in those events?
- Shawn
MCP, VB6: Desktop Apps
[ C# | VB | .NET | Java | VC++ | Perl | PHP | Javascript ]
Unless otherwise stated, all sample code provided is UNTESTED.
http://www.codemastershawn.com
-
August 26th, 2002, 08:12 AM
#3
Shawn,
Thanks for the quick reply, but as far as I know, nothing "fires" on the shutdown event. I just have a button on a form that has an "End" statement in it. I do have some fairly large arrays, but I even tried erasing them manually before the End statement. That didn't work either. It's my understanding that End is supposed to immediately terminate the program just as it did in vb3. ??
JB
-
August 26th, 2002, 08:46 AM
#4
END close the program immediately, destroying variable, but not OBJECT REFERENCE, if you have any object that reference to whatever, make sure you use SET objObject = nothing. Also, the END don't call the QueryUnload event and the Unload event, make sure you Unload formName each form of your projects. Make sure each class and .dll are destroyed by you, the END statement will not do it.
JeffB - hope it helps
-
August 26th, 2002, 09:22 AM
#5
JeffB,
Thanks. I did unload all forms and set them to nothing, but I may have some other objects I reference that I have not specifically addressed. I will try that. Is there any other way to "bail out" of a vb6 program without looking through thousands of lines of code I wrote a long time ago and make it stop "right now"?
Thanks,
JB
-
August 26th, 2002, 10:02 AM
#6
You can use that:
Code:
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Private Sub Command1_Click()
ExitProcess 0
End Sub
You CAN use that, but it is not the GOOD WAY to do it , well, it may not work 100%, if so you may take a look at TerminateProcess and GetCurrentProcessID.
I am not responsible for any problem encoutered by using that code
JeffB - hope it helps
-
August 26th, 2002, 12:12 PM
#7
JeffB,
Thank you, thank you, thank you! You're a genius! That appears to work.
-
August 29th, 2002, 02:24 PM
#8
Code:
as far as I know, nothing "fires" on the shutdown event.
With the exception of calling End (thanks Jeff - I didn't know End bypassed all that) - or ExitProcess, etc. - a VB program will typically fire the Query Unload and Unload events when it is shut down.
I had previously understood that it would also fire the Deactivate, LostFocus, Terminate, etc. events but I learned last night that I was mistaken.
Using ExitProcess (as Jeff has noted) is really a crude club and probably not the best solution. What I would suggest is to put a breakpoint on End and then use the debugging tools to try to determine what might still be running and/or loaded.
- Shawn
MCP, VB6: Desktop Apps
[ C# | VB | .NET | Java | VC++ | Perl | PHP | Javascript ]
Unless otherwise stated, all sample code provided is UNTESTED.
http://www.codemastershawn.com
-
August 29th, 2002, 10:42 PM
#9
Shawn,
Thanks for the input, but Jeff's "crude club" really works well. This is a stand-alone project that doesn't interact with other apps. I just want to kill it. I don't really care what it does after I say "quit". If I had time to make it end "elegantly" I would.
JB
-
August 30th, 2002, 09:23 AM
#10
ExitProcess
Since it seems like a crude club, here what MSDN say about ExitProcess:
From Microsoft MSDN
ExitProcess is the preferred method of ending a process. This function provides a clean process shutdown. This includes calling the entry-point function of all attached dynamic-link libraries (DLLs) with a value indicating that the process is detaching from the DLL. If a process terminates by calling TerminateProcess, the DLLs that the process is attached to are not notified of the process termination.
Since it exit the current process, it's like an END, but in better. TerminateProcess would be a less good way to end, but in anyway, looking MSDN, ExitProcess seem to be a good way to Exit an application. Let us know if you encounter any strange problem using ExitProcess.
JeffB
-
August 30th, 2002, 09:27 AM
#11
JeffB,
Thanks again. I feel even better about it now!
JB
-
September 1st, 2002, 02:53 PM
#12
Thanks for clarifying Jeff. It was TerminateProcess that I was thinking of. It's been a year or so since I've had a situation where I had to concern myself with these issues (and in that case I was trying to kill application A from application B). ExitProcess should be fine. TerminateProcess was the "club" I was thinking of.
- Shawn
MCP, VB6: Desktop Apps
[ C# | VB | .NET | Java | VC++ | Perl | PHP | Javascript ]
Unless otherwise stated, all sample code provided is UNTESTED.
http://www.codemastershawn.com
-
August 12th, 2004, 11:48 AM
#13
Hi JeffB,
I tried the following code you given but it also terminate my VB even it is in debug mode.... any solution
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Private Sub Command1_Click()
ExitProcess 0
End Sub
-
August 12th, 2004, 03:50 PM
#14
Since it is VB6 who is running your application, it is VB who is ending. There is nothing you can do about how the API works, but there is many way to make your application work differently depending of if it is in developpement mode or not. You could use a commandline parameters, conditional compilation or using simply a private variable (which should be easier):
Code:
Option Explicit
Private Const MODE_DEV = 0
Private Const MODE_EXE = 1
'You just need to change this value when compiling your EXE
Private Const mode = MODE_DEV
'Private Const mode = MODE_EXE
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Private Sub Command1_Click()
If mode = MODE_DEV Then
End
ElseIf mode = MODE_EXE Then
ExitProcess 0
End If
End Sub
Of course, it means you will not be using ExitProcess in debug mode. If your program don't terminate normally, you you can use VB to stop your application in developpement mode and when you compile, by changing the value of the variable, you will have an EXE that end with the ExitProcess API.
JeffB
-
August 12th, 2004, 07:32 PM
#15
vb6 slow shutdown
JeffB,
That's exactly the technique I have been using since you first gave me this ExitProcess idea a long time ago. It works great.
Thanks again,
JB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|