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 you to specify how many packages should be included in each group.
Usage
To use the ListAsync
method, you need to provide two parameters:
amountPerGroup
(Int32): The number of packages to include in each group. This determines the size of each page of results.
token
(CancellationToken): A token to monitor for cancellation requests. This allows the operation to be cancelled if needed.
The method returns a Task<ListResult>
, which represents the asynchronous operation. The ListResult
contains the results of the package listing operation.
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; // Number of packages per group
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 cancelled.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
}
}