当前位置: 首页>>代码示例>>C#>>正文


C# AsyncResult.CancelAsyncScanner方法代码示例

本文整理汇总了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,
//.........这里部分代码省略.........
开发者ID:bfmw,项目名称:ht4n,代码行数:101,代码来源:TestAsyncTableScanner.cs


注:本文中的AsyncResult.CancelAsyncScanner方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。