我有删除某些项目的代码:
private static void DeleteBatch(IList<TableEntity> toDelete)
{
if(toDelete == null)
throw new ArgumentNullException("toDelete");
if(toDelete.Count == 0)
throw new ArgumentException("There is no elements in toDelete.");
if(toDelete.GroupBy(e => e.PartitionKey).Count() > 1)
throw new ArgumentException("The entities to delete must have the same PartitionKey.");
Parallel.ForEach(Partitioner.Create(0, toDelete.Count, 100),
range =>
{
TableBatchOperation batchOperation = new TableBatchOperation();
for (Int32 i = range.Item1; i < range.Item2; i++)
batchOperation.Delete(toDelete[i]);
_table.ExecuteBatch(batchOperation);
});
}
表实体通过 * ETag 传递。
有时这会抛出一个StorageException: The specified resource does not exist.
我认为这是 404 HttpStatusCode。在这种情况下,我不在乎它是否不存在,所以我想忽略导致它们的操作的这个异常。如何忽略批处理中单个 TableOperations 的 404,或者至少重试未引发此异常的 TableOperations 的批处理操作(我怎么知道哪些操作失败了)。单独做每个操作只是为了能够找到导致404的原因,感觉非常无效。