Skip to content

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Attempt at asynchronous insert in Azure Table (not working). See
using System;
using System.Data.Services.Client;
using System.Diagnostics;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
namespace WorkerRole1
public class TableStorageWriter
private const string _tableName = "StorageTest";
private readonly CloudStorageAccount _storageAccount;
private readonly CloudTableClient _tableClient;
private TableServiceContext _context;
public TableStorageWriter()
_storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
_tableClient = _storageAccount.CreateCloudTableClient();
_context = _tableClient.GetDataServiceContext();
public void Write(string message)
DateTime now = DateTime.UtcNow;
var entity = new StorageTestEntity
Message = message,
PartitionKey = string.Format("{0:yyyy-MM-dd}", now),
RowKey = string.Format("{0:HH:mm:ss.fff}-{1}", now, Guid.NewGuid())
_context.AddObject(_tableName, entity);
// This statement works but it's synchronous
// context.SaveChangesWithRetries();
// This attempt at saving asynchronously results in System.ArgumentException:
// The current object did not originate the async result. Parameter name: asyncResult
(asyncResult => _context.EndSaveChanges(asyncResult)), null);
catch (StorageClientException e)
Debug.WriteLine("Error: {0}", e.Message);
Debug.WriteLine("Extended error info: {0} : {1}",
internal class StorageTestEntity : TableServiceEntity
public string Message { get; set; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.