立即下载文件和提取 - 另一个进程正在使用文件

时间:2014-11-17 20:31:46

标签: vb.net winforms .net-4.5 webclient

我循环浏览一个zip文件列表并从WebClient下载它们。我试图在下载后立即提取它们,但是收到另一个进程正在使用该文件的错误。

  

错误:进程无法访问文件&c; \ temp \ test.zip'因为它正被另一个进程使用。

我能想到的唯一一件事就是文件仍然可以使用"下载后的短时间内? DownloadFile会阻止("此方法会在下载资源时阻止。" - http://msdn.microsoft.com/en-us/library/ez801hhe(v=vs.110).aspx),因此我无法看到该文件仍在下载中存在问题。

关于变通办法的任何想法?

Using client As New WebClient
    oLog.Info("Downloading " & strFileServer & " to " & strFileLocal & "...")
    If Not Directory.Exists(strPathLocal) Then Directory.CreateDirectory(strPathLocal)
    client.DownloadFile(strFileServer, strFileLocal)
End Using

Using archive As ZipArchive = ZipFile.OpenRead(strFileLocal)
    For Each entry As ZipArchiveEntry In archive.Entries
        oLog.Info("Extracting " & entry.FullName & " to " & strPathLocal & "...")
        entry.ExtractToFile(strFileLocal, True)
    Next
End Using

0 个答案:

没有答案