Skip to content

Instantly share code, notes, and snippets.

@AndersNS
Created June 13, 2014 12:49
Show Gist options
  • Save AndersNS/b66b69929c6e7df754c9 to your computer and use it in GitHub Desktop.
Save AndersNS/b66b69929c6e7df754c9 to your computer and use it in GitHub Desktop.
Cancelationtoken method
async Task<int> ProcessObjectsAsync(List<SomeObjects> objectList, IProgress<int> progress,CancellationToken ct)
{
int processCount = await Task.Run<int>(() =>
{
foreach (var someObject in objectList)
{
ct.ThrowIfCancellationRequested();
// process next thing
}
}, ct);
return processCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment