I am trying to convert the following code to async/await:
long deletedBlobCount = 0;
Parallel.ForEach(BlobURLList, item => Interlocked.Add(ref deletedBlobCount, DeleteBlob(item)));
DeleteBlob(item)
function returns 1 if blob was deleted, 0 otherwise. This is what my new code looks like (I am on .Net 4):
long deletedBlobCount = 0;
var deleteBlobTask = new List<Task>();
foreach (var item in BlobURLList)
{
deleteBlobTask.Add(t => { Interlocked.Add(ref deletedBlobCount, await DeleteBlobAsync(item))});
}
Compiler doesn't like await DeleteBlobAsync(item) here. This is the error: The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier
What am I missing? Also, I can't make deletedBlobCount a class level variable (requirement for logging).