Skip to content

Instantly share code, notes, and snippets.

@takekazuomi
Created December 24, 2012 13:56
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Table;
namespace AsyncSemaphore
{
partial class Program
{
static void InsertAsync001(CloudTable table, int start, int count)
{
var tasks = Enumerable.Range(start, count).Select(async i =>
{
var e = new TableEntity(PKEY_STRS[i % PKEY_STRS.Length], i.ToString("D10"));
var insertOperation = TableOperation.Insert(e);
try
{
await table.ExecuteAsync(insertOperation).ConfigureAwait(false);
if (i != 0 && i % 100000 == 0)
Console.Error.WriteLine(i);
}
catch (StorageException se)
{
Console.Error.WriteLine("{0}, {1}", i, se.ToString());
}
}).ToArray();
Task.WhenAll(tasks);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment