完成解压缩过程后如何显示 MsgBox

How to show MsgBox after finishing unzip process

我有这个代码:

Private Sub KickoffExtract()
    actionStatus.Text = "Se instaleaza actualizarea.. va rugam asteptati."
    lblProgress.Text = "Se extrage..."
    Dim args(2) As String
    args(0) = GetSettingItem("./updUrl.info", "UPDATE_FILENAME")
    args(1) = extractPath
    _backgroundWorker1 = New System.ComponentModel.BackgroundWorker()
    _backgroundWorker1.WorkerSupportsCancellation = False
    _backgroundWorker1.WorkerReportsProgress = False
    AddHandler Me._backgroundWorker1.DoWork, New DoWorkEventHandler(AddressOf Me.UnzipFile)
    _backgroundWorker1.RunWorkerAsync(args)
End Sub

Private Sub UnzipFile(ByVal sender As Object, ByVal e As DoWorkEventArgs)
    Dim extractCancelled As Boolean = False
    Dim args() As String = e.Argument
    Dim zipToRead As String = args(0)
    Dim extractDir As String = args(1)
    Try
        Using zip As ZipFile = ZipFile.Read(zipToRead)
            totalEntriesToProcess = zip.Entries.Count
            SetProgressBarMax(zip.Entries.Count)
            AddHandler zip.ExtractProgress, New EventHandler(Of ExtractProgressEventArgs)(AddressOf Me.zip_ExtractProgress)
            zip.ExtractAll(extractDir, Ionic.Zip.ExtractExistingFileAction.OverwriteSilently)
        End Using
    Catch ex1 As Exception
        MessageBox.Show(String.Format("Actualizatorul a intampinat o problema in extragerea pachetului.  {0}", ex1.Message), "Error Extracting", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
    End Try
End Sub

Private Sub SetProgressBarMax(ByVal n As Integer)
    If ProgBar.InvokeRequired Then
        ProgBar.Invoke(New Action(Of Integer)(AddressOf SetProgressBarMax), New Object() {n})
    Else
        ProgBar.Value = 0
        ProgBar.Maximum = n
        ProgBar.Step = 1
    End If
End Sub

Private Sub zip_ExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
    If _operationCanceled Then
        e.Cancel = True
        Return
    End If

    If (e.EventType = Ionic.Zip.ZipProgressEventType.Extracting_AfterExtractEntry) Then
        StepEntryProgress(e)
    ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractAll) Then
    End If
End Sub

Private Sub StepEntryProgress(ByVal e As ExtractProgressEventArgs)
    If ProgBar.InvokeRequired Then
        ProgBar.Invoke(New ZipProgress(AddressOf StepEntryProgress), New Object() {e})
    Else
        ProgBar.PerformStep()
        System.Threading.Thread.Sleep(100)
        nFilesCompleted = nFilesCompleted + 1
        lblProgress.Text = String.Format("{0} din {1} fisiere...({2})", nFilesCompleted, totalEntriesToProcess, e.CurrentEntry.FileName)
        Me.Update()
    End If
End Sub

按钮上的这段代码:

If Not File.Exists("./" + GetSettingItem("./updUrl.info", "UPDATE_FILENAME")) Then
    MessageBox.Show("Actualizarea nu s-a descarcat corespunzator.", "Nu se poate extrage", MessageBoxButtons.OK)
End If

If Not String.IsNullOrEmpty("./" + GetSettingItem("./updUrl.info", "UPDATE_FILENAME")) And
   Not String.IsNullOrEmpty(extractPath) Then
    If Not Directory.Exists(extractPath) Then
        Directory.CreateDirectory(extractPath)
    End If
    nFilesCompleted = 0
    _operationCanceled = False
    btnUnzip.Enabled = False
    KickoffExtract()
End If

如何在完成解压缩过程后显示消息?我试过了

If ProgBar.Maximum Then
    MsgBox("finish")
End If

但它不起作用。我使用的是 dotnetzip 1.9,大部分代码来自 UnZip 示例。

如果您查看 BackgroundWorker 的文档,您会注意到有两个事件可以链接到代码中的事件处理程序。
其中之一是 RunWorkerCompleted,在 MSDN 页面中他们说

Occurs when the background operation has completed, has been canceled, or has raised an exception.

所以,写一个事件处理程序并绑定事件就可以了。

AddHandler Me._backgroundWorker1.RunWorkerCompleted, New RunWorkerCompletedEventHandler(AddressOf Me.UnzipComplete)

然后

Private Sub UnzipComplete(ByVal sender As System.Object, _
                          ByVal e As RunWorkerCompletedEventArgs) 
    If e.Cancelled = True Then
        MessageBox.Show("Canceled!")
    ElseIf e.Error IsNot Nothing Then
        MessageBox.Show("Error: " & e.Error.Message)
    Else
        MessageBox.Show("Unzip Completed!")
    End If
End Sub