Kill and restart the same application through code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helloitsme
    New Member
    • Oct 2006
    • 20

    Kill and restart the same application through code

    Hi!

    For a certain requirement, I need to kill the current application and restart the same application again. For that, I have the follofing code in the form-closing event of the application -

    Code:
    If myflag = false Then 
       Dim p As New System.Diagnostics.ProcessStartInfo()
       p.FileName = """" & My.Application.Info.DirectoryPath & "\" &   My.Application.Info.AssemblyName & ".exe" & """"
       p.WindowStyle = ProcessWindowStyle.Normal
       p.Verb = "open"
       p.UseShellExecute = True
       Dim myprocess As New System.Diagnostics.Process
       Me.Dispose()
       myprocess.Start(p)
       myprocess.WaitForExit()
    
    End If

    this does work as required, but every time the application reopens, an error message also appears saying - "myapplication. exe has encountered a problem and needs to close. We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost."

    any help would be greatly appreciated.

    thank you ...
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Maybe when the application reopens myflag is (still) set to false?

    Comment

    Working...