static Task<Sandbox.Package/ListResult> ListAsync( int amountPerGroup, CancellationToken token )

book_4_sparkGenerated
code_blocksInput

Description

The ListAsync method is a static method of the Sandbox.Package class. It asynchronously retrieves a list of packages, grouped by a specified amount, from the Asset Party service. This method is useful for fetching paginated results of packages, allowing for efficient data retrieval and processing.

Usage

To use the ListAsync method, you need to specify the number of packages per group and provide a cancellation token. The method returns a Task<ListResult>, which can be awaited to obtain the result of the operation.

Parameters:

  • amountPerGroup (Int32): The number of packages to include in each group.
  • token (CancellationToken): A token to monitor for cancellation requests.

Returns: A Task<ListResult> representing the asynchronous operation. The result contains the list of packages grouped as specified.

Example

// Example usage of ListAsync method
using System;
using System.Threading;
using System.Threading.Tasks;

public class PackageExample
{
    public async Task ListPackagesAsync()
    {
        int amountPerGroup = 10;
        CancellationToken cancellationToken = new CancellationToken();

        try
        {
            var result = await Sandbox.Package.ListAsync(amountPerGroup, cancellationToken);
            // Process the result
            foreach (var package in result.Packages)
            {
                Console.WriteLine($"Package: {package.Title}");
            }
        }
        catch (OperationCanceledException)
        {
            Console.WriteLine("Operation was canceled.");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"An error occurred: {ex.Message}");
        }
    }
}