2

I have 2 applications; one is the main program, the other is a mini updater program.

The idea is, by clicking a button on the main program you close it and call the updater.

However the updater crashes everytime saying it can't do anything with the main program because it is being used by another process. If I call the updater by itself it works just fine.

Is there any way to properly close the main application before updating?

Here's the code that calls the updater:

If UpdateAvailable() = True Then
    Process.Start(frm_Main.AppData & "\Updater.exe")
    Application.Exit()
End If

Updater code:

Dim myProcesses() As Process
Dim myProcess As Process
myProcesses = Process.GetProcessesByName("U-Certify Electrics Certificate Manager.exe")
For Each myProcess In myProcesses
    MsgBox(myProcess.ProcessName)
    myProcess.Kill()
Next
myProcess = Nothing
myProcesses = Nothing
Try
    My.Computer.FileSystem.RenameDirectory(ToReplace, BeReplaced)
    Return True
Catch ex As Exception
    MsgBox(ex.ToString)
    Return False
End Try

The program crashes when renaming the file that the main application is in.

Bugs
  • 4,491
  • 9
  • 32
  • 41
Bob.Tri
  • 55
  • 6
  • Your updater should wait for your application to be available for overwriting it. – Misery Mar 20 '17 at 11:22
  • I added a 20sec timer on the updater when it loads, to give plenty of time for the main application to close, but same thing happens – Bob.Tri Mar 20 '17 at 11:28
  • Try `Process.GetCurrentProcess().Kill()` instead of `Application.Exit` – Alex B. Mar 20 '17 at 11:38
  • Same thing still happens. Still says its being used by another process. – Bob.Tri Mar 20 '17 at 12:00
  • [This answer](http://stackoverflow.com/a/12978034/5897829) might help, use Environment.Exit() instead of Application.Exit() – Martin Verjans Mar 20 '17 at 12:41
  • I've tried Enviroment.Exit() and it still complains. Is there any way to check to see if a process is still running? – Bob.Tri Mar 20 '17 at 13:22
  • I've also used Shell as an alternative to Process.start() but same thing occurs. Is there really no way to call an application from another without having any ties to the first? – Bob.Tri Mar 22 '17 at 10:10

0 Answers0