如果远程服务器上有不同大小的可执行文件,我希望我的应用程序能够自我更新。我遇到的问题是,当我终止替换应用程序可执行文件的进程时,没有任何事情发生——eprocess.Kill()
即使我在文件替换过程中试图冻结线程,也没有任何事情发生。有什么我做错了吗?
这是我的代码:
Dim Request As System.Net.WebRequest
Dim Response As System.Net.WebResponse
Dim FileSize As Integer
Request = Net.WebRequest.Create("http://mywebsite.com/File.exe")
Request.Method = Net.WebRequestMethods.Http.Get
Response = Request.GetResponse
FileSize = Response.ContentLength
Dim mySize As New IO.FileInfo(Application.ExecutablePath)
If FileSize <> mySize.Length Then If File.Exists(tempPath & "\File_tmp.exe") Then
File.Delete(tempPath & "\File_tmp.exe")
End If
Patcher.DownloadFileAsync(New Uri("http://mywebsite.com/File.exe"), tempPath & "\File_tmp.exe") 'Patcher is defined before, you might think that its not working, but this is just a piece of code, and the new file is downloading properly. The described problem is
While Patcher.IsBusy
Threading.Thread.Sleep(100)
End While
Do While True
For Each eprocess As Process In Process.GetProcesses
If eprocess.ProcessName = "MyApplication" Then
eprocess.Kill()
End If
Next
File.Delete(Application.ExecutablePath)
'Copy downloaded file to the application executable path directory
File.Copy(tempPath & "\File_tmp.exe", Application.ExecutablePath)
Threading.Thread.Sleep(30) 'freeze thread...
Loop
End If