Re: Still my program is running :(
Hello,
Sorry to intervene.
Using End is really a very bad habit ans could be dangerous (fatal) in certain circumstances (sub-classing, certain hooks, and so on...)
The best is to definitely get rid of this bad habit (so that we never run any risk).
Best regards to you all.
Re: Still my program is running :(
Quote:
Originally Posted by
moa
Hello,
Sorry to intervene.
Using End is really a very bad habit ans could be dangerous (fatal) in certain circumstances (sub-classing, certain hooks, and so on...)
The best is to definitely get rid of this bad habit (so that we never run any risk).
Best regards to you all.
I rarely use it but it is not a bad habit if it is used correctly. The bad habit is using it instead of closing the objects created by your program. Technically the last line of code to execute in every program should be End. Ahead of which should be any code to release memory, close files, terminate objects and so forth.
If you use End and you have a fatal problem the problem is not with the end statement but with your other code. My advice would be that if you do not know how to realease the objects you have created then you should not be creating them. The usage of End or lack thereof is not the issue.
Re: Still my program is running :(
Consider this:
They still have old commands with new languages (to be backward compatible). There is an END statement in VB.Net.
It should NOT be used, because of *unpredictable* results.
VB.Net allows threads to start other threads. They can call other objects, and consume memory, and then properly destroy them.
If you stop the program using END, the OS no longer even *KNOWS* about those threads.
What happens next is *unpredictable*.
END is bad, and if you can find a place where it *HAS* to be used, then acknowledge it, awarding lots of points, if it can't be re-written,
Re: Still my program is running :(
i did all the suggessions and still my program is running.
i check for undestroyed object i ceated.
put the program terminations codes under form unload event etc. non of them workd.
Code:
Shell_NotifyIcon NIM_DELETE, t
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
Unload frm
Set frm = Nothing
End If
Next
End
its true that i use many 3d party ocx, dlls, and classes. so now i think probably the problem is with one of them. cant this be?
Re: Still my program is running :(
This just works fine :D
Code:
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, t
' Dim frm As Form
' For Each frm In Forms
' If frm.Name <> Me.Name Then ' Unload this form LAST
' Unload frm
' Set frm = Nothing
' End If
' Next
End
End Sub
shall i go for it :D
I no a big dicsussion is going on regarding End :D
Re: Still my program is running :(
Interesting
Try this:
Code:
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, t
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
Unload frm
Set frm = Nothing
End If
Next
If Not frm Is Nothing Then
Debug.Print "hey, it's not nothing!"
Set frm = Nothing
End If
End
End Sub
Also, with any variations you've tried, has there been any difference between running from the IDE, and fully compiled?
Re: Still my program is running :(
Quote:
Originally Posted by
WizBang
Interesting
Try this:
Code:
Private Sub Form_Unload(Cancel As Integer)
Shell_NotifyIcon NIM_DELETE, t
Dim frm As Form
For Each frm In Forms
If frm.Name <> Me.Name Then ' Unload this form LAST
Unload frm
Set frm = Nothing
End If
Next
If Not frm Is Nothing Then
Debug.Print "hey, it's not nothing!"
Set frm = Nothing
End If
End
End Sub
Also, with any variations you've tried, has there been any difference between running from the IDE, and fully compiled?
i put this code and removed the old code in the unload event, nothing is printed. but now i see the exe is terminated :confused:
really confusing.
i complied and check but putting a msgbox "hey, it's not nothing!"
noting displayed.
Re: Still my program is running :(
sorry sorry, Again exe remains with above code, it look like some time it does and some time it does not :confused:
i mean after performing some actions,
Re: Still my program is running :(
If it exits ok only if you haven't had it do anything, then one or more of those external dependencies you mentioned may be suspect.
Re: Still my program is running :(
If all fails, we could try a direct kick at the process, (which is like using brute force), terminating the process which has created the window you are in.
You need to declare three API functions and write one sub which I called KickMe()
Code:
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long _
) As Long
Private Declare Function TerminateProcess Lib "kernel32" ( _
ByVal hProcess As Long, ByVal uExitCode As Long _
) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" ( _
ByVal hwnd As Long, lpdwProcessId As Long _
) As Long
Private Sub KickMe()
Dim PID As Long
Dim Pro As Long
'get the process ID of this window
GetWindowThreadProcessId Me.hwnd, PID
'get a process handle for this
Pro = OpenProcess(PROCESS_ALL_ACCESS, 0&, PID)
'terminate this process
TerminateProcess Pro, 0&
End Sub
If you put the above code in your Form which is the starting object of your application, it's process should be completely eliminated by calling KickMe. You could put this call into the Form_Unload(), or for testing just drop a CommandButton on your form and call it from the _Click() event.
But note: If you run this code in the IDE, the complete IDE is terminated, because in the end the IDE was the creator of the Form when starting the program.
So put this in, SAVE your code and THEN test it.
Re: Still my program is running :(
Quote:
Originally Posted by
WoF
If all fails, we could try a direct kick at the process, (which is like using brute force), terminating the process which has created the window you are in.
You need to declare three API functions and write one sub which I called KickMe()
Code:
Private Const PROCESS_ALL_ACCESS = &H1F0FFF
Private Declare Function OpenProcess Lib "kernel32" ( _
ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long _
) As Long
Private Declare Function TerminateProcess Lib "kernel32" ( _
ByVal hProcess As Long, ByVal uExitCode As Long _
) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" ( _
ByVal hwnd As Long, lpdwProcessId As Long _
) As Long
Private Sub KickMe()
Dim PID As Long
Dim Pro As Long
'get the process ID of this window
GetWindowThreadProcessId Me.hwnd, PID
'get a process handle for this
Pro = OpenProcess(PROCESS_ALL_ACCESS, 0&, PID)
'terminate this process
TerminateProcess Pro, 0&
End Sub
If you put the above code in your Form which is the starting object of your application, it's process should be completely eliminated by calling
KickMe. You could put this call into the Form_Unload(), or for testing just drop a CommandButton on your form and call it from the _Click() event.
But note: If you run this code in the IDE,
the complete IDE is terminated, because in the end the IDE was the creator of the Form when starting the program.
So put this in, SAVE your code and THEN test it.
hey wof, hmm, another simple solution. currently i am using another exe to terminate my app process and terminate itself. works charm. any way, i ll try this one also.
Re: Still my program is running :(
The "END" did not work for me,
this is what happens
click program tray icon to launch the Magnifer of my application, now if i click "exit program" menu item (which has set to "end") the program terminates and the magnifer window remains freezed on the screen and the process also running.
other solution , unload all the forums and unlaod the main form also did not work, even after that i put end.
Re: Still my program is running :(
This Magnifier you mention; does this mean you have a timer running continuously?
Re: Still my program is running :(
Re: Still my program is running :(
but wizbang,
even if i open the 'about' window and close the main from form tray, that closes and process remian.