I am trying to load some arbitrary GPS data (150 million records) into Azure Table storage using Parallel.For and async await. But I am getting the following error in the first await statement:
The 'await' operator can only be used within an async lambda expression. Consider marking this lambda expression with the 'async' modifier.
Here is my code:
private static async Task GenerateGpsPointsForTruckAsync(int counter, CloudTableClient tableClient)
{
// Create a dummy VIN
string vin = counter.ToString("D17");
Random random = new Random();
DateTime start = new DateTime(2010, 1, 1);
int range = (DateTime.Today - start).Milliseconds;
// Create the batch operation.
TableBatchOperation batchOperation = new TableBatchOperation();
// Prepare 10 batches of 100 GPS points
Parallel.For(0, 10, i =>
{
for (int j = 0; j < 99; j++)
{
Location location = new Location(vin, start.AddDays(random.Next(range)).ToString());
location.Coordinates = new GeoCoordinate(random.Next(30, 45), random.Next(75, 100));
batchOperation.Insert(location);
}
await Task.Run(async () =>
{
await LoadGpsPointsForTruckAsync(tableClient, batchOperation);
});
});
}
I looked at a few solutions on Stack Overflow but they don't seem to be working for me.
asyncmodifier on the lambda you create on theParallel.For(0, 10, i => ...line. Could you try adding one there as well? - Tamás Demeawait Task.Run(...instead of simplyawait LoadGpsPointsForTruckAsync(...);- Alex