Xceed .NET Libraries Documentation
NumAutoRetries Property


Xceed.Zip Assembly > Xceed.Zip Namespace > ZipArchive Class : NumAutoRetries Property
Gets or sets the number of times certain operations will be automatically retried when an exception occurs.
Syntax
'Declaration
 
Public Shared Property NumAutoRetries As Integer
'Usage
 
Dim value As Integer
 
ZipArchive.NumAutoRetries = value
 
value = ZipArchive.NumAutoRetries
public static int NumAutoRetries {get; set;}

Property Value

An System.Int32 value that represents the number of times certain operations will be automatically retried. The default value is 0.
Remarks

No retries will be attempted if the value of the property is zero or less.

Automatic retries currently only apply to operations where a zip archive is updated and the required temporary files fail to be moved, renamed or deleted.

This usually happens because another service or application, antivirus software for example, have locked the files.

Combined with the AutoRetryDelay Property, the temporary file operations will be tried again, giving the conflicting application time to finish its work.

Example
public static void AutoRetry()
{
  // Enable auto retries by asking for 5 retries
  ZipArchive.NumAutoRetries = 5;

  // Set up a delay of 200ms between retries
  ZipArchive.AutoRetryDelay = 200;

  // Select a file that will be our zip file
  AbstractFile zipFile = new DiskFile( "AutoRetry1.zip" );

  // If the zip file already exists
  if( zipFile.Exists )
    // Delete it
    zipFile.Delete();

  // Create a logical zip archive around the zip file
  ZipArchive zip = new ZipArchive( zipFile );

  // Wrap the operations that modify the zip archive in a batch update
  using( AutoBatchUpdate batch = new AutoBatchUpdate( zip ) )
  {
    // Select an individual file
    AbstractFile sourceFile = new DiskFile( @"SomeFile.dat" );

    // Select a specific target name and path for the file in the archive
    AbstractFile targetFile = zip.GetFile( @"MyFolder1\MyFolder2\MyNamedFile.mydata" );

    // Zip it to the archive
    sourceFile.CopyTo( targetFile, true );
  }

  // Wrap the operations that modify the zip archive in a batch update
  using( AutoBatchUpdate batch = new AutoBatchUpdate( zip ) )
  {
    // Select an individual file
    AbstractFile sourceFile = new DiskFile( @"SomeOtherFile.dat" );

    // Select a specific target name and path for the file in the archive
    AbstractFile targetFile = zip.GetFile( @"MyFolder1\MyFolder2\MyNamedFile.mydata" );

    /* We will now update the existing item in the archive. If the temporary files
       somehow cannot be moved, renamed or deleted because of interference from another
       application, the component will retry because we set the 'auto retry' properties
       above.
       
       Note that this will happen during the closure of the AutoBatchUpdate block we are
       in. */

    // Update the item in the archive
    sourceFile.CopyTo( targetFile, true );
  }
}
    Public Shared Sub AutoRetry()
      ' Enable auto retries by asking for 5 retries
      ZipArchive.NumAutoRetries = 5

      ' Set up a delay of 200ms between retries
      ZipArchive.AutoRetryDelay = 200

      ' Select a file that will be our zip file
      Dim zipFile As AbstractFile = New DiskFile("AutoRetry1.zip")

      ' If the zip file already exists
      If zipFile.Exists Then
        ' Delete it
        zipFile.Delete()
      End If

      ' Create a logical zip archive around the zip file
      Dim zip As New ZipArchive(zipFile)

      ' Wrap the operations that modify the zip archive in a batch update
      Using batch As New AutoBatchUpdate(zip)
        ' Select an individual file
        Dim sourceFile As AbstractFile = New DiskFile("SomeFile.dat")

        ' Select a specific target name and path for the file in the archive
        Dim targetFile As AbstractFile = zip.GetFile("MyFolder1\MyFolder2\MyNamedFile.mydata")

        ' Zip it to the archive
        sourceFile.CopyTo(targetFile, True)
      End Using

      ' Wrap the operations that modify the zip archive in a batch update
      Using batch As New AutoBatchUpdate(zip)
        ' Select an individual file
        Dim sourceFile As AbstractFile = New DiskFile("SomeOtherFile.dat")

        ' Select a specific target name and path for the file in the archive
        Dim targetFile As AbstractFile = zip.GetFile("MyFolder1\MyFolder2\MyNamedFile.mydata")

'         We will now update the existing item in the archive. If the temporary files
'           somehow cannot be moved, renamed or deleted because of interference from another
'           application, the component will retry because we set the 'auto retry' properties
'           above.
'           
'           Note that this will happen during the closure of the AutoBatchUpdate block we are
'           in. 

        ' Update the item in the archive
        sourceFile.CopyTo(targetFile, True)
      End Using
    End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ZipArchive Class
ZipArchive Members
AutoRetryDelay Property