避免在VB.NET中异步下载文件后出现“进程无法访问该文件,因为它正被其他进程使用”之类的错误
所以,我遵循了这个教程:我已经做了所有类似的,正如作者所说的 问题是,当我想打开下载的文件时,我无法打开,因为引发了一个异常:进程无法访问该文件,因为它正被另一个进程使用 我已经检查是否存在webclient的Dispose函数,但它没有任何作用。。。我不知道还能做什么,你建议我做什么避免在VB.NET中异步下载文件后出现“进程无法访问该文件,因为它正被其他进程使用”之类的错误,vb.net,asynchronous,download,process.start,Vb.net,Asynchronous,Download,Process.start,所以,我遵循了这个教程:我已经做了所有类似的,正如作者所说的 问题是,当我想打开下载的文件时,我无法打开,因为引发了一个异常:进程无法访问该文件,因为它正被另一个进程使用 我已经检查是否存在webclient的Dispose函数,但它没有任何作用。。。我不知道还能做什么,你建议我做什么 提前感谢。请看这一行: Download(fileDownload, fileCheck) 您正在传递导致错误的filecheckfile,我想您写错了一个应该是 Download(fileDownload,
提前感谢。请看这一行:
Download(fileDownload, fileCheck)
您正在传递导致错误的filecheckfile,我想您写错了一个应该是
Download(fileDownload, fileOpen)
coz文件路径应为process.Start中描述的可执行文件的文件
复习
下面是一个功能完整的代码,它看起来正是您的:
Dim fsave As String = "C:\Users\Giorgio\Desktop\tp1.exe"
Sub Main()
WebClientTest()
Console.ReadLine()
End Sub
Private Sub WebClientTest()
Dim wb As New WebClient
AddHandler wb.DownloadFileCompleted, AddressOf DownloadCompleted
wb.DownloadFileAsync(New Uri("http://sourceforge.net/projects/audacity/files/audacity/2.0.5/audacity-win-2.0.5.exe/download"), fsave)
Console.WriteLine("Run download")
End Sub
Private Sub DownloadCompleted(ByVal sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs)
Console.WriteLine("DownloadCompleted")
Process.Start(fsave)
End Sub
它工作正常,在process.start时加载audacity.exe没有问题
使该进程更改事件显示您的文件是否有问题,例如,如果总字节数为=到-1,则文件源中有错误。对不起,我必须更新我没有重新发布的代码,该变量。。。这是一个txt,我写了一些文字。。。但它与下载或可执行文件没有任何关系。。。请重新检查代码;好的,我会修好的。。。问题是我在下载过程中调用了这个函数,但我没有意识到这一点。。。现在我把它修好了P
Dim fsave As String = "C:\Users\Giorgio\Desktop\tp1.exe"
Sub Main()
WebClientTest()
Console.ReadLine()
End Sub
Private Sub WebClientTest()
Dim wb As New WebClient
AddHandler wb.DownloadFileCompleted, AddressOf DownloadCompleted
wb.DownloadFileAsync(New Uri("http://sourceforge.net/projects/audacity/files/audacity/2.0.5/audacity-win-2.0.5.exe/download"), fsave)
Console.WriteLine("Run download")
End Sub
Private Sub DownloadCompleted(ByVal sender As Object, e As System.ComponentModel.AsyncCompletedEventArgs)
Console.WriteLine("DownloadCompleted")
Process.Start(fsave)
End Sub