public void CloudTableCreateIfNotExistsAPM() { CloudTableClient tableClient = GenerateCloudTableClient(); string tableName = GenerateRandomTableName(); CloudTable tableRef = tableClient.GetTableReference(tableName); try { // Assert Table does not exist Assert.IsFalse(tableRef.Exists()); using (ManualResetEvent evt = new ManualResetEvent(false)) { IAsyncResult result = null; tableRef.BeginCreateIfNotExists((res) => { result = res; evt.Set(); }, null); evt.WaitOne(); // Table should have been created Assert.IsTrue(tableRef.EndCreateIfNotExists(result)); } // Assert Table exists Assert.IsTrue(tableRef.Exists()); using (ManualResetEvent evt = new ManualResetEvent(false)) { IAsyncResult result = null; tableRef.BeginCreateIfNotExists((res) => { result = res; evt.Set(); }, null); evt.WaitOne(); // Table should not have been created Assert.IsFalse(tableRef.EndCreateIfNotExists(result)); } } finally { tableRef.DeleteIfExists(); } }