Results 1 to 3 of 3

Thread: Kill task

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    75

    Kill task

    Hi whats the simplest way to kill a running process?
    I've tried

    Code:
    Dim proc() as process = nothing  
    proc = Process.GetProcessesByName("mytestfile.exe")  
    For i As Integer = 0 To proc.Count - 1  
        proc(i).CloseMainWindow()  
    Next I

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    75

    Re: Kill task

    got it

    Dim myprocess() As Process = System.Diagnostics.Process.GetProcessesByName("mytestfile")
    For Each mykill As Process In myprocess

    mykill.Kill()
    Next

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: Kill task

    Actually, you probably ought to be using a combination of the two. Calling CloseMainWindow is like clicking the Close button on the title bar of the app's main window while Kill is like using End Task in the Task Manager. The latter should only be used as a last resort or for processes that have no main window. If CloseMainWindow might work then you should call it. You can then call WaitForExit and specify a time limit, then call Kill if it still hasn't exited.

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