當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。