public static Task CreateAsync(this CloudTable tbl, TableRequestOptions opt, OperationContext ctx, CancellationToken token) { ICancellableAsyncResult result = null; if (opt == null && ctx == null) { result = tbl.BeginCreate(null, null); } else { result = tbl.BeginCreate(opt, ctx, null, null); } var cancellationRegistration = token.Register(result.Cancel); return(Task.Factory.FromAsync(result, ar => { cancellationRegistration.Dispose(); try { tbl.EndCreate(ar); } catch (StorageException se) { // Todo: Use the PnP azure retry block here for transient exceptions throw; } })); }
/// <summary> /// Creates a table asynchronously. /// </summary> /// <param name="cloudTable">Cloud table.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>Task.</returns> public static Task CreateAsync( this CloudTable cloudTable, CancellationToken cancellationToken = default(CancellationToken)) { ICancellableAsyncResult asyncResult = cloudTable.BeginCreate(null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return(Task.Factory.FromAsync( asyncResult, result => { registration.Dispose(); cloudTable.EndCreate(result); })); }
public ICancellableAsyncResult BeginCreate(AsyncCallback callback, object state) { return(_cloudTable.BeginCreate(callback, state)); }