When performing multiple operations on a folder, the process can take a while to complete. Although events can provide feedback during these lengthy operations, it is also possible to reduce the time it takes to accomplish all the operations if the folder class being used implements the IBatchUpdateable interface.
The IBatchUpdateable interface is defined within the Xceed.FileSystem namespace and is implemented by the "Archive" classes, namely, the ZipArchive, TarArchive and GZipArchive classes.
The IBatchUpdateable interface implements the BeginUpdate and EndUpdate methods which allow you to determine a scope at the end of which all the modifications made to a folder will be committed. Using this interface increases the speed at which the operations on the folder are accomplished since the modifications are not committed to the folder each time a method is called but rather only once for all the operations when the EndUpdate method is called.
If a class implements the IBatchUpdateable interface, the BeginUpdate and EndUpdate methods can be called directly on the class. The following example shows how to do this with a Zip archive:
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
The AutoBatchUpdate class will verify to see that the folder class passed in its constructor implements the IBatchUpdateable interface and will automatically call the BeginUpdate and EndUpdate methods if it does. If the folder class does not implement the IBatchUpdateable interface, the code will be executed normally.
To perform batch updates, the following steps must be performed:
Verify if the folder class implements the IBatchUpdateable interface. This can only be done via the root of the folder.
If the IBatchUpdateable interface is implemented, call the BeginUpdate method to mark the begin of your scope.
Do the various operations on the folder.
To commit the modifications made to the folder, call the EndUpdate method. It is important to make sure that the EndUpdate method is always called otherwise the modifications will not be committed.
This example demonstrates how to use the IBatchUpdateable interface directly:
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
using Xceed.FileSystem |
This example demonstrates how to use the AutoBatchUpdate class rather than manually calling the BeginUpdate and EndUpdate methods manually:
VB.NET | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|