CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 33
  1. #16
    Join Date
    Oct 2006
    Posts
    327

    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.

  2. #17
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Still my program is running :(

    Quote Originally Posted by moa View Post
    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.

  3. #18
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    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,
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #19
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    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?
    "Don't Bring A Knife To A Gun Fight"

  5. #20
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    Re: Still my program is running :(

    This just works fine

    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
    I no a big dicsussion is going on regarding End
    "Don't Bring A Knife To A Gun Fight"

  6. #21
    Join Date
    Dec 2001
    Posts
    6,332

    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?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  7. #22
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    Re: Still my program is running :(

    Quote Originally Posted by WizBang View Post
    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
    really confusing.
    i complied and check but putting a msgbox "hey, it's not nothing!"
    noting displayed.
    "Don't Bring A Knife To A Gun Fight"

  8. #23
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    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
    i mean after performing some actions,
    "Don't Bring A Knife To A Gun Fight"

  9. #24
    Join Date
    Dec 2001
    Posts
    6,332

    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.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  10. #25
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    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.

  11. #26
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    Re: Still my program is running :(

    Quote Originally Posted by WoF View Post
    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.
    "Don't Bring A Knife To A Gun Fight"

  12. #27
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    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.
    "Don't Bring A Knife To A Gun Fight"

  13. #28
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Still my program is running :(

    This Magnifier you mention; does this mean you have a timer running continuously?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  14. #29
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    Re: Still my program is running :(

    hmm, yah yah
    "Don't Bring A Knife To A Gun Fight"

  15. #30
    Join Date
    Jul 2007
    Location
    in your pocket
    Posts
    339

    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.
    "Don't Bring A Knife To A Gun Fight"

Page 2 of 3 FirstFirst 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured