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


C# Chain.ExecuteAsync方法代码示例

本文整理汇总了C#中Chain.ExecuteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Chain.ExecuteAsync方法的具体用法?C# Chain.ExecuteAsync怎么用?C# Chain.ExecuteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chain的用法示例。


在下文中一共展示了Chain.ExecuteAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public static void Run()
        {
            Chain<int, double> chain = new Chain<int, double>()
            .Link<int>(x =>
            {
                // Generate random array of ints
                int[] nums = new int[x];
                Random rand = new Random();
                for (int i = 0; i < x; i++)
                {
                    nums[i] = rand.Next(100);
                }
                return nums;
            })
            .Link<int[]>(x =>
            {
                // order the numbers (pointless but why not)
                return x.OrderBy(y => y).ToArray();
            })
            .Link<int[]>(x =>
            {
                // compute the average and return it
                double average = 0.0;
                for (int i = 0; i < x.Length; i++)
                {
                    average += x[i];
                }
                return average / x.Length;
            });

            int count = 0;
            int started = 0;

            chain.ExecuteFinished += (sender, e) =>
            {
                Interlocked.Increment(ref count);
            };

            int iters = 1000000;

            Queue<int> diff = new Queue<int>(iters);

            Stopwatch sw = Stopwatch.StartNew();
            for (int i = 0; i < iters; i++)
            {
                started++;
                chain.ExecuteAsync(10);

                diff.Enqueue(started - count);
            }
            sw.Stop();

            Console.WriteLine("Took: " + sw.Elapsed.ToString());
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:54,代码来源:AsyncBenchmark.cs

示例2: TestAsyncExecution

        public void TestAsyncExecution()
        {
            Chain<int, int> chain = new Chain<int, int>()
            .Link<int>(x => x + 1)
            .Link<int>(x => x + 1)
            .Link<int>(x => x + 1)
            .Link<int>(x => x + 1);

            int output = -1;
            chain.ExecuteFinished += (sender, e) => output = e.Output;

            chain.ExecuteAsync(0);

            SpinWait.SpinUntil(() => output != -1, 250);

            Assert.AreEqual<int>(4, output);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:17,代码来源:AsyncTests.cs

示例3: Run

        public static void Run()
        {
            Chain<int, double> chain = new Chain<int, double>()
                .Link<int>(x =>
                {
                    // Generate random array of ints
                    int[] nums = new int[x];
                    Random rand = new Random();
                    for (int i = 0; i < x; i++)
                    {
                        nums[i] = rand.Next(100);
                    }
                    return nums;
                })
                .Link<int[]>(x =>
                {
                    // order the numbers (pointless but why not)
                    return x.OrderBy(y => y).ToArray();
                })
                .Link<int[]>(x =>
                {
                    // compute the average and return it
                    double average = 0.0;
                    for (int i = 0; i < x.Length; i++)
                    {
                        average += x[i];
                    }
                    return average / x.Length;
                });

            chain.ExecuteFinished += (sender, e) =>
            {
                Console.WriteLine("Async execute finished, result: " + e.Output);
            };

            // Start execution of our chain, passing in a large initial argument so it takes some time
            chain.ExecuteAsync(10000);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:38,代码来源:AsyncAverage.cs

示例4: TestAsyncExecutionError

        public void TestAsyncExecutionError()
        {
            Chain<int, int> chain = new Chain<int, int>()
            .Link<int>(x => x + 1)
            .Link<int>(x =>
            {
                if (x == 1)
                    throw new Exception(x.ToString());
                else
                    return x + 1;
            })
            .Link<int>(x => x + 1)
            .Link<int>(x => x + 1);

            Exception ex = null;
            chain.ExecuteFinished += (sender, e) =>
            {
                ex = e.Exception;
            };

            chain.ExecuteAsync(0);

            SpinWait.SpinUntil(() => ex != null, 250);

            Assert.IsNotNull(ex);
            Assert.AreEqual<bool>(true, ex is ChainExecutionException);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:27,代码来源:AsyncTests.cs

示例5: TestAsyncTypeError

        public void TestAsyncTypeError()
        {
            Chain<int, int> chain = new Chain<int, int>()
            .Link<int>(x => x + 1)
            .Link<int>(x => x + "1")
            .Link<int>(x => x + 1)
            .Link<int>(x => x + 1);

            Exception ex = null;
            chain.ExecuteFinished += (sender, e) =>
            {
                ex = e.Exception;
            };

            chain.ExecuteAsync(0);

            SpinWait.SpinUntil(() => ex != null, 250);

            Assert.IsNotNull(ex);
            Assert.AreEqual<bool>(true, ex is LinkArgumentException);
        }
开发者ID:bodyloss,项目名称:Chains,代码行数:21,代码来源:AsyncTests.cs


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