Xceed .NET Libraries Documentation
ItemProgression event

Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Events > ItemProgression event

The ItemProgression event is raised each time a FileSystemItem object is about to be processed by a method call, providing progression information to the handler. 

Keep in mind that using the ItemProgression event increases the time it takes to process the files. The reason behind this is that the data will be scanned twice. The first time the files are scanned, information regarding the files will be accumulated ( filename, size, etc.. ). This is to allow accurate progress information to be returned during the second run.

Purpose

The main purpose of the ItemProgression event is to provide feedback to the user during lengthy operations. For example, if we wanted to delete a folder and all it's sub-directories, the process could take a while and the application could appear to be frozen. To notify the user that the application is still in the process of completing the operation, you can update a progress bar in the event handler for the ItemProgression event.

Basic steps - C#

To subscribe to the ItemProgression event, the following steps must be performed:

Basic steps - VB.NET

To subscribe to the ItemProgression event, the following steps must be performed:

Demonstration

This example demonstrates how to delete a folder located on disk and display progress information during the operation.

VB.NET Copy Code

Imports Xceed.FileSystem

Dim WithEvents fiEvents As New FileSystemEvents()
Dim folder As New DiskFolder("c:\temp")

folder.Delete( fiEvents, Nothing )

Private Sub fiEvents_ItemProgression(ByVal sender As Object, _
                                      ByVal e As Xceed.FileSystem.ItemProgressionEventArgs) Handles fiEvents.ItemProgression

  ListBox1.Items.Add("Processed " + e.AllItems.Processed + _
                     " bytes of " + e.AllItems.Total + _
                     " on " + e.CurrentItem.Name)
End Sub

C# Copy Code

using Xceed.FileSystem;

FileSystemEvents fiEvents = new FileSystemEvents();
fiEvents.ItemProgression += new ItemProgressionEventHandler( OnItemProgression );
 
DiskFolder folder = new DiskFolder( @"c:\temp" );
folder.Delete( fiEvents, null );
 
//This method will handle the ItemProgression events that are raised.
public static void OnItemProgression( object sender, ItemProgressionEventArgs e )
{
  Console.WriteLine( "Processed {0} bytes of {1} on {2}.",
                     e.AllItems.Processed,
                     e.AllItems.Total,
                     e.CurrentItem.Name );
}
 
//If you no longer wish to handle the events that are raised,
//you can unsubscribe from the event notifications by doing the following:
 
fiEvents.ItemProgression -= new ItemProgressionEventHandler( OnItemProgression );