Skip to content

Instantly share code, notes, and snippets.

@mantzas
Created May 26, 2016 19:52
Show Gist options
  • Save mantzas/ae8012f45e11cee367ed5986851f643e to your computer and use it in GitHub Desktop.
Save mantzas/ae8012f45e11cee367ed5986851f643e to your computer and use it in GitHub Desktop.
public async Task<int> ProcessMessagesAsync(List<string> messages, IProgress<int> progress)
{
int totalCount = messages.Count;
int processCount = await Task.Run<int>(() =>
{
int tempCount = 0;
foreach (var message in messages)
{
Console.WriteLine(message);
if (progress != null)
{
progress.Report((tempCount * 100 / totalCount));
}
tempCount++;
}
return tempCount;
});
return processCount;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment