Chilkat Event Callbacks in VB.NET (.NET Core)
Here’s a VB .NET Core example using the Chilkat .NET Core assembly to create a Zip archive with support for the following event callbacks:
PercentDone
— to track zip creation progressAbortCheck
— to allow canceling the operationProgressInfo
— to monitor additional info
While this example focuses on callbacks for creating a .zip, the same method applies to other Chilkat .NET Core classes like Http, Ftp2, MailMan, and Rest.
Important: Event callbacks differ between .NET Core
and .NET Framework
.
See Chilkat VB.NET Event Callbacks in .NET Framework
Imports Chilkat
Public Class Form1
Dim WithEvents zip As New Chilkat.Zip
Private Sub handleAbortCheck(ByRef abort As Boolean)
Application.DoEvents()
abort = CheckBox1.Checked
End Sub
Private Sub handlePercentDone(pctDone As Integer, ByRef abort As Boolean)
ProgressBar1.Value = pctDone
Application.DoEvents()
abort = CheckBox1.Checked
End Sub
Private Sub handleProgressInfo(name As String, value As String)
Debug.WriteLine($"[ProgressInfo] {name}: {value}")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim glob As New Chilkat.Global
Dim success As Boolean = glob.UnlockBundle("YOUR_CHILKAT_UNLOCK_CODE")
' Add event callbacks
zip.setAbortCheckCb(AddressOf handleAbortCheck)
zip.setPercentDoneCb(AddressOf handlePercentDone)
zip.setProgressInfoCb(AddressOf handleProgressInfo)
' AbortCheck callbacks are called every 250 milliseconds.
' (A PercentDone callback counts as an AbortCheck.)
sftp.HeartbeatMs = 250
Dim zipPath As String = "c:/temp/myFiles.zip"
' Initialize the zip object, which also sets the FileName property to the path of the zip to be created.
Zip.NewZip(zipPath)
' Append references to files to be zipped.
Dim recurse As Boolean = True
success = Zip.AppendFiles("c:/workarea/*.*", recurse)
If (success = False) Then
Debug.WriteLine(Zip.LastErrorText)
Exit Sub
End If
' Write the .zip and close the zip file (and clears the zip object).
success = Zip.WriteZipAndClose()
If (success = False) Then
Debug.WriteLine(Zip.LastErrorText)
Exit Sub
End If
Debug.WriteLine("Successfully created " & zipPath)
End Sub
End Class