Skip to content

LINQ AsyncExtensions

ZZZ Projects edited this page Jan 24, 2016 · 2 revisions

Async Extension methods to perform operation on LINQ to objects asynchronously.

// Using Z.Linq

public Task<IEnumerable<Customer>> MyAsyncMethod(CancellationToken cancellationToken)
{
    List<Customer> customers = DB.GetCustomers();
    var task = list.WhereAsync(c => c.IsActive, cancellationToken);

    // ... synchronous code ...
    
    return task;
}

If a cancellationToken is used, "ThrowIfCancellationRequested()" is invoked in the Enumerator.MoveNext() method.