Request

Response

    Creating a Custom Progress Reporter

    The Progress Reporter utility in the SDK is designed to simplify the process of tracking and displaying the progress of multiple asynchronous tasks. It accepts a progress message and a list of tasks to be observed, abstracting away the calculation of completed tasks and the logic to update the UI with the progress status.

    Progress updates are published in the format: “{Message} {CompletedTasks} of {TotalTasks}”. For example, “Uploading Geometries 2 of 5”.

    Features

    • Simplified Progress Tracking: Automatically calculates the number of completed tasks and updates the progress status.
    • UI Updates: Provides real-time progress updates to the UI.
    • Customizable Messages: Allows you to specify custom messages to be displayed alongside the progress status.

    Usage Example

    Below is a sample code that demonstrates how to use the Progress Reporter utility to track the progress of a list of long-running asynchronous tasks.

    // List of long running async tasks
    List<Task> customTasks = new List<Task>();
    for (int i = 0; i < 5; i++)
    {
        customTasks.Add(this.LongRunningDummyAsyncTask(i));
    }
    
    // Pass list of tasks to ProgressReporter utility along with a Message to be displayed on screen
    new ProgressReporter(Client).ConfigureProgressReporterFor("Custom Tasks", customTasks);
    
    // Await tasks completion after passing them to ProgressReporter
    await Task.WhenAll(customTasks);
    
    // Sample long running async task
    private async Task LongRunningDummyAsyncTask(int i)
    {
        await Task.Delay(500 * i);
    }
    
    Show More

    Detailed Explanation

    1. Creating a List of Tasks:

      List<Task> customTasks = new List<Task>();
      for (int i = 0; i < 5; i++)
      {
          customTasks.Add(this.LongRunningDummyAsyncTask(i));
      }
      
      • This code snippet creates a list of long-running asynchronous tasks. Each task is added to the customTasks list.
    2. Configuring the Progress Reporter:

      new ProgressReporter(Client).ConfigureProgressReporterFor("Custom Tasks", customTasks);
      
      • This line of code initializes a new instance of the ProgressReporter class and configures it to monitor the list of tasks (customTasks). The progress message “Custom Tasks” will be displayed alongside the progress status.
    3. Awaiting Task Completion:

      await Task.WhenAll(customTasks);
      
      • This line of code waits for all tasks in the customTasks list to complete. It ensures that the application does not proceed until all tasks have finished executing.
    4. Sample Long-Running Asynchronous Task:

      private async Task LongRunningDummyAsyncTask(int i)
      {
          await Task.Delay(500 * i);
      }
      
      • This is a sample implementation of a long-running asynchronous task. The task simply delays for a specified amount of time (500 * i milliseconds) to simulate a long-running operation.

    The Progress Reporter utility is a powerful tool for managing and displaying the progress of multiple asynchronous tasks in your .NET applications. By abstracting away the complexities of progress tracking and UI updates, it allows you to focus on the core logic of your application.