VB Code:
Dim frm as Form For Each frm in Forms Unload frm Set frm=Nothing Next End
Printable View
VB Code:
Dim frm as Form For Each frm in Forms Unload frm Set frm=Nothing Next End
_
Who said he uses timers?
oooops i'm sorry i didn't see that "End" at the end... :D :D :D
Have you tested this theory?
Yeah, works perfect ;)
You could put:Quote:
Originally posted by James Stanich
Have you tested this theory?
VB Code:
app.taskvisible = false
instead of:
VB Code:
END
if you use "End" you had better be sure that you close any resources that you open via API's or dll's...
What does that have to do with closing ur application?Quote:
Originally posted by Nightwalker83
You could put:
VB Code:
app.taskvisible = false
It's just to hide ur app from the windows tasklist
Using:Quote:
Originally posted by phrozeman
What does that have to do with closing ur application?
It's just to hide ur app from the windows tasklist
VB Code:
Unload me
or
VB Code:
unload f
Would just unload the application but it would still show in the windows tasklist. :rolleyes:
true, but i would still recommend using End instead of taskvisible. end does more than just removing the app from tasklist, which once the forms are unloaded properly, is a good thing
Err, that only happens if you terminate your application in a bad way, or your computer is majorly screwed up, because I've never needed it...
You'd want app.taskvisible=false if it takes a while to unload and you don't want your average user to notice. However, it does nothing with respect to unloading your program.
Using:Quote:
Originally posted by snakeeyes1000
true, but i would still recommend using End instead of taskvisible. end does more than just removing the app from tasklist, which once the forms are unloaded properly, is a good thing
VB Code:
END
Is always bad practise because your program would crash.
I know but I have always had my application still show in the task window after I have closed it using:Quote:
You'd want app.taskvisible=false if it takes a while to unload and you don't want your average user to notice. However, it does nothing with respect to unloading your program.
VB Code:
unload me 'Or whatever
I just add:
VB Code:
app.taskvisible=false
To make sure I don't get this problem after the program finishes.
The problem with using app.taskvisible = false is that it won't unload your application! It'll only make it seem like it has been unloaded.
If it isn't unloading when you do unload me, then you need to make sure that no functions being called after "unload me" are referencing any forms or anything in or on forms.
Go ahead and attach a simple project where after the "unload me" statement (and ALL the forms have to be unloaded, not hidden), it does not disappear from the taskbar.
:rolleyes: I meant use it like this:Quote:
The problem with using app.taskvisible = false is that it won't unload your application! It'll only make it seem like it has been unloaded.
VB Code:
Private Sub Command1_Click() App.TaskVisible = False Unload Me End Sub
On some computers the application name stayed in the Task List after using:
VB Code:
unload me
That why I added it in I am NOT say you have to use it though.
Yep, definately a good point Aaron.
I would also recommend chucking a Form.Visible = false line as well, makes for a slightly smother affect when a program closes. ;)
Ok, so, how's the VB.Net version of James' code?
The reason you are needing to put app.taskvisible = false or End after a form unload is because your unload ISNT unloading and destroying the form, but leaving a reference out there that you didn't cleanup. Try putting a:
where formname is the actual form name in the unload event of the form.Code:
set formname = nothing
Do not use
If you unload the form and destroy its reference (assuming you have done the same for any other object you have created) you will not need End OR app.taskvisible = falseCode:
set me = nothing
If you bothered to read the posts you would have noticed that I have already stated what you have said.Quote:
Originally posted by VBGuy
The reason you are needing to put app.taskvisible = false or End after a form unload is because your unload ISNT unloading and destroying the form, but leaving a reference out there that you didn't cleanup. Try putting a:
where formname is the actual form name in the unload event of the form.Code:
set formname = nothing
Do not use
If you unload the form and destroy its reference (assuming you have done the same for any other object you have created) you will not need End OR app.taskvisible = falseCode:
set me = nothing
So how come when I use this code in VB.net the "forms" part is underlined like an error?
Because this code is meant for VB6?
So whats the code for "The proper way to exit an application" for VB.net, if you please.
why can't we use simply:
Why all this. I have always used only End and have not found anything wrong with it!!Quote:
End
End doesn't clean up memory used by your program and such. One of the guys will give you the list of why its a bad idea. ;)
How about............
___________________________
Private Sub Form_Unload()
Set Me = Nothing
End Sub
___________________________
???????
Well, nothing, except for the fact that it won't compile.Quote:
Originally posted by PaulyWally
How about............
___________________________
Private Sub Form_Unload()
Set Me = Nothing
End Sub
___________________________
???????
;)
Sorrrrrrrrrrrryyyyyyy......... :)
___________________________
Private Sub Form_Unload()
Set frmFormName = Nothing
End Sub
___________________________
Wow. What a reponse for such a simple task.... :D
I hope you never get into subclassing. ;)Quote:
Originally posted by Skill Jaan
why can't we use simply:
Why all this. I have always used only End and have not found anything wrong with it!!
Are you sure about that?Quote:
Originally posted by Pc_Madness
End doesn't clean up memory used by your program and such. One of the guys will give you the list of why its a bad idea. ;)
I mean any memory you open up yourself doing anything tricky - fair enough you should clean up afterwards, but surely VB6 does its own garbage collection for normal stuff like forms? Certainly I can't find anything in the VB samples or documentation about this (sure somebody will now prove me wrong) and it seems like an important thing to document if it's true.
We have a large and complex application that we run all day on several PC's. A timer closes it with a simple END statement each night and the PC's stay on 24/7 for the backup tape to run. If what you say is true, I would expect to see some memory getting chewed up each day - but Task Manager does not show any memory leakage at all.
Now I've set myself up as a target, somebody want to take a shot?
Here's a great reason to not use End...
Run the attached code and click the button. :)
Edit: Whoops. The code is located three posts down. :(
Frightening...Quote:
Originally posted by The Hobo
Here's a great reason to not use End...
Run the attached code and click the button. :)
Using End in the Form_[Query]Unload() is bad. Using it elsewhere in your application is even worse. Why?
Slap a CommandButton on your form, name it cmdEnd, and run this code:
VB Code:
Private Sub cmdEnd_Click() End End Sub Private Sub Form_Unload(Cancel As Integer) MsgBox "I was called!" End Sub
What doesn't happen? :)
Whoops. The attached code:
Well yes. Obviously if you go outside of native VB with a dll call to deliberately allocate memory and don't free it, of course you will have a problem.
But if you simply have a number of forms open and call End from a module, VB seems to clean up after itself.
I can't see it's possible to write a universal 'catch all' exit procedure guaranteed to clean up everything. You just have to do it on a case by case basis. And I'm not convinced you need to set any open forms to Nothing before Ending, so long as the End statement is not inside one of them. Vb seems to do that automatically. At least that is what experimentation seems to show. Anyone got sample code to demonstrate to the contrary?
Easy way around that...
Just make the call BEFORE you send End.
VB Code:
Private Sub cmdEnd_Click() Form_Unload End Sub Private Sub Form_Unload() Unload Me MsgBox "I was called" End End Sub
I think this has been beaten to death, wouldn't you say?
I agree. This threads nearly as long as your signatureQuote:
Originally posted by crptcblade
I think this has been beaten to death, wouldn't you say?
:)
Now that's just redundant if you ask me. If the Form_Unload() has been called, your application will end afterwards. So why call End?Quote:
Originally posted by hothead
Easy way around that...
Just make the call BEFORE you send End.
VB Code:
Private Sub cmdEnd_Click() Form_Unload End Sub Private Sub Form_Unload() Unload Me MsgBox "I was called" End End Sub
That was supposed to be Form_QueryUnload.
If you look on Planet Source Code, search for BFChat, and look under the same sub inside the Client portion (bfcc.vbp I think it is), you'll see an example of this in action.
If the user tries to exit while it's trying to connect, the program displays a message box telling you to wait. It doesn't call End yet until either it's completely connected, or fails to connect.
If the user tries to exit, and the winsock state is not trying to connect, it will just exit as usual. Then look in your Task Manager if you're running XP. You will find that it's not under the Applications or Progresses tabs anymore. It has freed up the memory used by the program, as it's supposed to do.
Granted the dude's code's a bit messed up (it takes some doing to figure out what the variables he used are for), but I think this is a good example of how you can do what you tried to do in your End.vbp file.
'on some OS however, it will take it as this program is not
'responding
Private Sub Form_queryUnload()
cancel=1
MsgBox "You wanna **** down? No way"
End
End Sub
for the part about closeing appliactions or other things i just do
VB Code:
Private Sub Form_Unload(Cancel As Integer) End End Sub
sometimes i call on it for what ever reasons that might be
VB Code:
Unload Form1
if i dont have a unload or end. the app will just keep running even tho when u hit the [x] button it will hide the app but still be showing up in the taskbar manager.
It's amazing to me how often "how to close an app" leads to long repititious discussions. IMHO, James' first post shows the proper way to end an app. (BTW, please don't respond if you don't agree. As I said there's been a lot of discussion about this and any more would be pretty much pointless).Quote:
Originally posted by stonie
for the part about closeing appliactions or other things i just do
VB Code:
Private Sub Form_Unload(Cancel As Integer) End End Sub
sometimes i call on it for what ever reasons that might be
VB Code:
Unload Form1
if i dont have a unload or end. the app will just keep running even tho when u hit the [x] button it will hide the app but still be showing up in the taskbar manager.
Hi Marty.Quote:
Originally posted by MartinLiss
It's amazing to me how often "how to close an app" leads to long repititious discussions. IMHO, James' first post shows the proper way to end an app. (BTW, please don't respond if you don't agree. As I said there's been a lot of discussion about this and any more would be pretty much pointless).
I do agree that the first post is the answer (although it's really a kludge to catch mistakes you made elsewhere), so presumably I can reply.
Don't you think discussion is healthy in its own right?
It promotes social interaction. And isn't discussion the entire point of a Forum?
Granted, some discussions are long rambling and pointless - but as long as they give the participants some satisfaction, why not? Nobody needs to read threads they do not want to. (Unless they are a moderator of course :) )
Can't see any problem here, unless we are running out of disk-space or bandwidth. (We aren't are we?)
I always Use Unload Me
And usually
VB Code:
Private Sub Form_Unload(Cancel As Integer, UnloadMode As Integer) 'Add my code here Unload Me End 'Whatever End Sub
Somone should lock this thread. I'm tired of rinding on the merry-go-round.
I agree.