private void Index(IEnumerable <ITableEntity> entities, CloudTable table) { int exceptionCount = 0; while (true) { try { var options = new TableRequestOptions() { PayloadFormat = TablePayloadFormat.Json, MaximumExecutionTime = _Timeout, ServerTimeout = _Timeout, }; var batch = new TableBatchOperation(); int count = 0; foreach (var entity in entities) { batch.Add(TableOperation.InsertOrReplace(entity)); count++; } if (count > 1) { table.ExecuteBatch(batch, options); } else { if (count == 1) { table.Execute(batch[0], options); } } if (exceptionCount != 0) { IndexerTrace.RetryWorked(); } break; } catch (Exception ex) { IndexerTrace.ErrorWhileImportingEntitiesToAzure(entities.ToArray(), ex); exceptionCount++; if (exceptionCount > 5) { throw; } Thread.Sleep(exceptionCount * 1000); } } }