public void CloudTableDeleteIfExistsAPM() { 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.BeginDeleteIfExists((res) => { result = res; evt.Set(); }, null); evt.WaitOne(); // Table should not have been deleted as it doesnt exist Assert.IsFalse(tableRef.EndDeleteIfExists(result)); } // Assert Table exists tableRef.Create(); Assert.IsTrue(tableRef.Exists()); using (ManualResetEvent evt = new ManualResetEvent(false)) { IAsyncResult result = null; tableRef.BeginDeleteIfExists((res) => { result = res; evt.Set(); }, null); evt.WaitOne(); // Table should have been deleted Assert.IsTrue(tableRef.EndDeleteIfExists(result)); } // Assert Table Was Deleted Assert.IsFalse(tableRef.DeleteIfExists()); } finally { tableRef.DeleteIfExists(); } }