本文介绍了如何在VB.NET中完成解压缩进程(dotnetzip)后启动msgbox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!我有这个代码:



Hello! I have this code:

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





和这个代码在一个按钮:



and this code on a button:

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





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



我尝试了什么:



i试过:



how can I show a message after complete the unzip process?

What I have tried:

i tried:

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





但它不起作用



but it doesn't works

推荐答案

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





和zip.ExtractProgress处理程序后的这个事件处理程序



and this event handler after zip.ExtractProgress handler

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


这篇关于如何在VB.NET中完成解压缩进程(dotnetzip)后启动msgbox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 16:03