【发布时间】:2015-09-13 18:02:18
【问题描述】:
我是 VB.NET 的新手,我在 Google 上搜索了很多,但找不到答案。
我希望程序下载一个 zip 文件并使用 BackgroundWorker 解压缩它。
我有下载代码,但找不到如何使用 BackgroundWorker 解压缩文件。
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
downloadFile("https://dl.dropboxusercontent.com/u/85542087/test.exe", "test.exe")
Status.Text = "Downloading file from W4H Servers...."
End Sub
Private Sub downloadFile(ByVal srcPath As String, ByVal destPath As String)
Dim wClient As New System.Net.WebClient()
AddHandler wClient.DownloadProgressChanged, AddressOf downloadFile_ProgressChanged
wClient.DownloadFileAsync(New System.Uri(srcPath), destPath)
Status.Text = "Downloading file from W4H Servers...."
End Sub
Private Sub downloadFile_ProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Status.Text = "Downloading file from W4H Servers...."
ProgressBar1.Maximum = e.TotalBytesToReceive
ProgressBar1.Value = e.BytesReceived
Application.DoEvents()
If e.ProgressPercentage = 100 Then
'download completed
System.Threading.Thread.Sleep(2000)
Me.Close()
Form1.Close()
Process.Start("test.exe")
End If
End Sub
以上代码将下载我的文件到 .exe 执行路径并从那里运行。所以我想在那里提取并运行它。
压缩包为“test.zip”,其中包含“test.exe”。
【问题讨论】:
-
我使用 DotNetZip- 添加 dll 但工作正常。据我所知,没有用于从 .zip 文件解压缩或提取文件的 Windows 或 .Net 解决方案。
-
我使用了 SharpZipLib (icsharpcode.github.io/SharpZipLib),效果很好。除非它是一个非常大的文件,否则您可能真的不需要 BackgroundWorker 来执行此操作。解压缩一个典型的 .exe 应该不到一秒钟。
-
您需要不关注如何使用后台工作人员解压缩文件,而是关注两个不同的问题 - 使用后台工作人员 --> msdn.microsoft.com/en-us/library/cc221403%28v=vs.95%29.aspx 和解压文件。一旦你有了解压文件的代码,你就可以在
bgwDoWork运行它——完成
标签: vb.net