locked
killing a process in task manager RRS feed

  • Question

  • What have I to do if I want to kill a process in my task manager?

    My application name is
    BackupAll.exe
    and it is, obviously, in my tsk manager when it runs.

    When I close it, while it is burning a dvd (using nero com object), the form closes but in task manager BackupAll.exe still exists!!
    How can I kill it DEFINITEVELY when I close my application?
    Is there a simple and effective way?

    Thanks!!

    Well,
    if I close my application, while it is NOT burning a dvd (using nero com object), the form closes and in task manager BackupAll.exe disappears.
    Sunday, December 4, 2005 5:53 PM

Answers

  • Yep, you are forcing a shutdown by killing the process.

    This is a bad thing, you should never need to call Process.Kill or (CloseMainWindow for that matter).

    It's worse than calling Application.Exit().

    Also the Process.Close() method simply disposes of the of the process object itself and doesn't 'close' the process.

    You really need to track down why your application isn't closing.

    Did you try what I suggested above?

    Try starting off with an empty windows application and keep adding things until your application won't quit and the last thing you have added caused the problem.

    Thursday, December 15, 2005 7:51 PM

All replies

  • You probably don't want to force an exit in this situation. Is there a cancel on the nero COM object?

    Also you need to make sure that you are calling Marshal.ReleaseComObject on any COM objects you are using once you have finished with them.
    Sunday, December 4, 2005 8:13 PM
  • I'll try this way:


        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            Me.BackgroundWorker1.CancelAsync()
            Me.BackgroundWorker2.CancelAsync()
            nero.Abort()

            Dim y As Integer
            y = System.Runtime.InteropServices.Marshal.ReleaseComObject(nero)
            Do Until y = 0
                y = System.Runtime.InteropServices.Marshal.ReleaseComObject(nero)
            Loop
        End Sub

        Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            Me.Dispose()
            Application.ExitThread()
            Application.Exit()
        End Sub

     


    Is it correct?
    Monday, December 5, 2005 10:07 AM
  • Depending on how you are running the Form, you may not need all the code in the Form1_FormClosed event. If you are using the new Visual Basic application framework then you shouldn't need any of the Form1_FormClosed method.

    Monday, December 5, 2005 10:33 AM
  • Yes, you're right.

    I deleted that part of code.

    My problem is still there.
    How can I kill a process (my application) in task manager?
    It is still there even if my form is closed...


    I want that, when I close my main form (form1), my application (and any thread originated by it) is killed.


    ThanksSmile
    Monday, December 5, 2005 2:23 PM
  • Okay there is obviously some sort of object (probably your COM CD burner objects) still floating around.

    Try starting off with an empty windows application and keep adding things until your application won't quit and the last thing you have added caused the problem.

    Once you have done that, post back here and we will try to solve this.

    Thursday, December 8, 2005 9:03 AM
  • Thank you very much.
    I solved my problem with these lines:

        Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As_
     System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
            nero.Abort()

            Me.BackgroundWorker1.CancelAsync()
            Me.BackgroundWorker2.CancelAsync()

            'deleting definitevely nero com object
            Dim y As Integer
            y = System.Runtime.InteropServices.Marshal.ReleaseComObject(nero)
            Do Until y = 0
                y = System.Runtime.InteropServices.Marshal.ReleaseComObject(nero)
            Loop

        End Sub

        Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As_

     System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
            System.Diagnostics.Process.GetCurrentProcess.CloseMainWindow()
            System.Diagnostics.Process.GetCurrentProcess.Close()
            System.Diagnostics.Process.GetCurrentProcess.Kill()
        End Sub


    Now when I close the main window-form (the only one!) all resources are released e process disappears from task manager!
    Thank you everybody.
    If you have some comments about my solution please let me know!

    Thursday, December 15, 2005 11:54 AM
  • Yep, you are forcing a shutdown by killing the process.

    This is a bad thing, you should never need to call Process.Kill or (CloseMainWindow for that matter).

    It's worse than calling Application.Exit().

    Also the Process.Close() method simply disposes of the of the process object itself and doesn't 'close' the process.

    You really need to track down why your application isn't closing.

    Did you try what I suggested above?

    Try starting off with an empty windows application and keep adding things until your application won't quit and the last thing you have added caused the problem.

    Thursday, December 15, 2005 7:51 PM