本文整理汇总了C#中AsyncResult.CancelAsyncScanner方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncResult.CancelAsyncScanner方法的具体用法?C# AsyncResult.CancelAsyncScanner怎么用?C# AsyncResult.CancelAsyncScanner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncResult
的用法示例。
在下文中一共展示了AsyncResult.CancelAsyncScanner方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScanTableCancelAsyncScanner
public void ScanTableCancelAsyncScanner()
{
if (!HasAsyncTableScanner) {
return;
}
var rng = new Random();
for (var r = 0; r < 5; ++r) {
var ca = 0;
var caLimit = rng.Next(CountA / 2);
var caTotal = 0;
var cb = 0;
var cbLimit = rng.Next(CountB / 2);
var cbTotal = 0;
var cc = 0;
using (var asyncResult = new AsyncResult()) {
table.BeginScan(
asyncResult,
new ScanSpec().AddColumn("a"),
(ctx, cells) =>
{
ca += cells.Count;
if (caTotal == 0 && ca > caLimit) {
caTotal = ca;
return AsyncCallbackResult.Cancel;
}
return AsyncCallbackResult.Continue;
});
table.BeginScan(
asyncResult,
new ScanSpec().AddColumn("a", "b", "c"),
(ctx, cells) =>
{
cb += cells.Count;
if (cbTotal == 0 && cb > cbLimit) {
cbTotal = cb;
return AsyncCallbackResult.Cancel;
}
return AsyncCallbackResult.Continue;
});
table.BeginScan(
asyncResult,
new ScanSpec().AddColumn("b", "c"),
(ctx, cells) =>
{
cc += cells.Count;
return AsyncCallbackResult.Continue;
});
asyncResult.Join();
Assert.IsNull(asyncResult.Error, asyncResult.Error != null ? asyncResult.Error.ToString() : string.Empty);
Assert.IsTrue(asyncResult.IsCompleted);
Assert.IsFalse(asyncResult.IsCancelled);
Assert.AreEqual(caTotal, ca);
Assert.AreEqual(cbTotal, cb);
Assert.AreEqual(CountB + CountC, cc);
ca = 0;
caLimit = rng.Next(CountA / 2);
caTotal = 0;
cb = 0;
cbLimit = rng.Next(CountB / 2);
cbTotal = 0;
cc = 0;
table.BeginScan(
asyncResult,
new ScanSpec().AddColumn("a"),
(ctx, cells) =>
{
ca += cells.Count;
if (caTotal == 0 && ca > caLimit) {
caTotal = ca;
asyncResult.CancelAsyncScanner(ctx);
}
return AsyncCallbackResult.Continue;
});
table.BeginScan(
asyncResult,
new ScanSpec().AddColumn("a", "b", "c"),
(ctx, cells) =>
{
cb += cells.Count;
if (cbTotal == 0 && cb > cbLimit) {
cbTotal = cb;
asyncResult.CancelAsyncScanner(ctx);
}
return AsyncCallbackResult.Continue;
});
table.BeginScan(
asyncResult,
//.........这里部分代码省略.........