private void InsertComplete(IAsyncResult result) { _table.EndExecute(result); //Get the next item to insert lock (_pending) { _executing--; if (_pending.Count % 100 == 0) { Debug.WriteLine("{0} records pending", _pending.Count); } if (_executing == 0 && _pending.Count == 0) { Debug.WriteLine("No pending city inserts"); } if (_pending.Count > 0) { InsertCity(_pending.Dequeue()); } } }
/// <summary> /// Executes table operation asynchronously. /// </summary> /// <param name="cloudTable">Cloud table.</param> /// <param name="tableOperation"> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableOperation" /> object that represents the operation to perform. /// </param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns> /// A <see cref="T:Microsoft.WindowsAzure.Storage.Table.TableResult" /> containing the result of executing the operation on the table. /// </returns> public static Task <TableResult> ExecuteAsync( this CloudTable cloudTable, TableOperation tableOperation, CancellationToken cancellationToken = default(CancellationToken)) { ICancellableAsyncResult asyncResult = cloudTable.BeginExecute(tableOperation, null, null); CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null); return(Task <TableResult> .Factory.FromAsync( asyncResult, result => { registration.Dispose(); return cloudTable.EndExecute(result); })); }
public static Task <TableResult> ExecuteAsync(this CloudTable tbl, TableOperation operation, TableRequestOptions opt, OperationContext ctx, CancellationToken token) { ICancellableAsyncResult result = null; if (opt == null && ctx == null) { result = tbl.BeginExecute(operation, null, null); } else { result = tbl.BeginExecute(operation, opt, ctx, null, null); } var cancellationRegistration = token.Register(result.Cancel); return(Task.Factory.FromAsync(result, ar => { cancellationRegistration.Dispose(); return tbl.EndExecute(ar); })); }
public TableResult EndExecute(IAsyncResult asyncResult) { return(_cloudTable.EndExecute(asyncResult)); }