Xceed Zip Compression Library Documentation
Running multiple operations at the same time
Xceed Zip control reference > Running multiple operations at the same time

The Xceed Zip Compression Library  ActiveX control supports both the Single-Threaded Apartment model (STA) and the Multi-Threaded Apartment model (MTA). The entire library's code is threadsafe, can be instantiated multiple times in order to perform multiple zip file manipulation operations at the same time, and is designed to use very little memory per instance – so your machine won't run out of memory when you're running dozens of instances at the same time.

The library also supports background processing. Background processing is a different concept than running multiple instances simultaneously. See the background processing property topic for details.

Any restrictions?

Yes, two small restrictions. First: two or more instances may not add files to, or create the same zip file located in the same folder. Second: each instance of the Xceed Zip control can only execute one process at a time. This makes sense, because if it was possible for a single instance to run more than one operation at a time, you would get the same event from two processes and wouldn't know for which process you are getting the event. Running multiple simultaneous operations involves having multiple instances, with each instance running its own operation.

How is it done?

If you're using forms in your application, you can place multiple Xceed Zip control objects on your form, call them XceedZip1, XceedZip2, XceedZip3, etc. Each control on the form is a separate instance of the library. Therefore, each instance's methods can be called simultaneously and can each process at the same time.

For example, place 4 Xceed Zip controls on a form, with 4 buttons, and 4 progress bars. For the click event of Button1, add code to zip up a file that referring to the XceedZip1 control. Set Button1's caption to the return value so you can know when it finished. In the XceedZip1 control's GlobalStatus event, set ProgressBar1's value to the nBytesPercent parameter provided to you by the GlobalStatus event. Do this 4 times, changing Button1 for Button2, XceedZip1 for XceedZip2, and ProgressBar1 for ProgressBar2. Make sure each button works on a different zip file! Now run your program, and click on each button one after the other. If you are zipping up enough files, each progress bar should be moving along at its own pace.

If you're using code, it's pretty much the same concept: Instantiate the control multiple times and instruct each instance to do whatever you want it to. In VB, to create multiple instances of the control, you can do this (this example can be generalized to more objects to n by using arrays):

Visual Basic Copy Code

' Make sure you added the Xceed Zip control to your object references. To do this, go to the Project menu and select the "References..." menu item, then checkmark the Xceed Zip Compression Library v5.0 entry in the list of components. 

' Here we define the types for our variables
Dim WithEvents MyZipInstance1 As XceedZip
Dim WithEvents MyZipInstance2 As XceedZip
Dim WithEvents MyZipInstance3 As XceedZip
Dim WithEvents MyZipInstance4 As XceedZip

Dim ResultCode1 As xcdError
Dim ResultCode2 As xcdError
Dim ResultCode3 As xcdError
Dim ResultCode4 As xcdError

' Now we instantiate each variable with an Xceed Zip control
Set MyZipInstance1 = New XceedZip
Set MyZipInstance2 = New XceedZip
Set MyZipInstance3 = New XceedZip
Set MyZipInstance4 = New XceedZip

' Because we are running all 4 simultaneously from sequential code,
' we'll turn on background processing so that each of the following 4
' lines is immediately executed, instead of first running the first line,
' waiting for it to complete, then running the second line, etc.
XceedZip1.BackgroundProcessing = True
XceedZip2.BackgroundProcessing = True
XceedZip3.BackgroundProcessing = True
XceedZip4.BackgroundProcessing = True 

' Lets set our zip files to work with
XceedZip1.ZipFilename = "c:\temp\zipfile1.zip"
XceedZip2.ZipFilename = "c:\temp\zipfile2.zip"
XceedZip3.ZipFilename = "c:\temp\zipfile3.zip"
XceedZip4.ZipFilename = "c:\temp\zipfile4.zip"

' Which files to zip up
XceedZip1.FilesToProcess = "c:\temp\folder1\*"
XceedZip2.FilesToProcess = "c:\temp\folder2\*"
XceedZip3.FilesToProcess = "c:\temp\folder3\*"
XceedZip4.FilesToProcess = "c:\temp\folder4\*" 

' Start all the zipping! (All result codes should = xecProcessStarted
ResultCode1 = XceedZip1.Zip
ResultCode2 = XceedZip2.Zip
ResultCode3 = XceedZip3.Zip
ResultCode4 = XceedZip4.Zip 

' The rest of your code will continue executing, too. The only thing
' left is to write a handler for the ProcessCompleted event for each Xceed Zip instance,
' so you can get the xResult variable which will provide you with the real return
' value for each of the 4 zip calls above.