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


C# Pipeline.Push方法代码示例

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


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

示例1: DisposeTest2

        public void DisposeTest2()
        {
            bool failed = false;
            Pipeline<int> pipeline = new Pipeline<int>((i) => {
                Thread.Sleep(50);
                failed = true; // this should not run because the dispose will kill the thread before it gets scheduled
            });

            pipeline.Push(1);
            pipeline.Dispose();
            pipeline.Push(0);
            Assert.True(!failed);
        }
开发者ID:jburman,项目名称:razordb,代码行数:13,代码来源:PipelineTests.cs

示例2: MultiThreadedPipeline

        public void MultiThreadedPipeline()
        {
            int finalTotal = 0;
            int lastNumber = -1;
            bool pipelineInOrder = true;

            Pipeline<int> FinishPipeline = new Pipeline<int>((i) => {
                if (Interlocked.Increment(ref lastNumber) != i) {
                    pipelineInOrder = false;
                }
                finalTotal += i;
            });
            Pipeline<int> WaitPipeline = new Pipeline<int>((i) => {
                if ((i & 1) == 0) {
                    Thread.Sleep(5); // force items to come in out of order
                } else {
                    Thread.Sleep(1);
                }
                FinishPipeline.OrderedPush(i,i);
            },10,2);
            Pipeline<int> FirstPipeline = new Pipeline<int>((i) => {
                WaitPipeline.Push(i);
            });

            for (int i = 0; i < 200; i++) {
                FirstPipeline.Push(i);
            }

            Console.WriteLine("Done pushing.");
            FirstPipeline.WaitForDrain();
            WaitPipeline.WaitForDrain();
            FinishPipeline.WaitForDrain();
            Console.WriteLine("Max 0: {0} Max 1: {1} Max 2: {2}", FirstPipeline.MaxQueueSize, WaitPipeline.MaxQueueSize, FinishPipeline.MaxQueueSize);
            Console.WriteLine("Done.");
            Assert.AreEqual(19900, finalTotal);
            Assert. True(pipelineInOrder);
        }
开发者ID:jburman,项目名称:razordb,代码行数:37,代码来源:PipelineTests.cs

示例3: StopTest

        public void StopTest()
        {
            Pipeline<int> pipeline = new Pipeline<int>((i) => {
                Console.WriteLine("Processing {0}.", i);
            });

            for (int i = 0; i < 5; i++) {
                pipeline.Push(i);
            }

            pipeline.WaitForDrain();
            pipeline.Push(0);
        }
开发者ID:jburman,项目名称:razordb,代码行数:13,代码来源:PipelineTests.cs

示例4: PipelineTest2

        public void PipelineTest2()
        {
            Pipeline<int> Waiting2Pipeline = new Pipeline<int>((i) => {
                Thread.Sleep(50);
                Console.WriteLine("Waited 50ms. => {0}", i);
            });
            Pipeline<int> DoublePipeline = new Pipeline<int>((i) => {
                Console.WriteLine("Double {0} => {1}", i, i*2);
                Waiting2Pipeline.Push(i * 2);
            });
            Pipeline<int> HalfPipeline = new Pipeline<int>((i) => {
                Console.WriteLine("Half {0} => {1}", i, i/2);
                DoublePipeline.Push(i/2);
            });

            HalfPipeline.Push(10);
            Console.WriteLine("Pushed 10.");
            HalfPipeline.Push(500);
            Console.WriteLine("Pushed 500.");
            HalfPipeline.Push(1000);
            Console.WriteLine("Pushed 1000.");

            HalfPipeline.WaitForDrain();
            DoublePipeline.WaitForDrain();
            Waiting2Pipeline.WaitForDrain();
            Console.WriteLine("Done.");
        }
开发者ID:jburman,项目名称:razordb,代码行数:27,代码来源:PipelineTests.cs

示例5: PipelineTest

        public void PipelineTest()
        {
            Pipeline<int> pipeline = new Pipeline<int>((i) => {
                Console.WriteLine("Processing {0}.", i);
            });

            Console.WriteLine("Starting.");
            pipeline.Push(0);
            Console.WriteLine("Pushed 0.");
            pipeline.Push(1);
            Console.WriteLine("Pushed 1.");
            pipeline.Push(2);
            Console.WriteLine("Pushed 2.");
            pipeline.Push(3);
            Console.WriteLine("Pushed 3.");
            pipeline.WaitForDrain();
            Console.WriteLine("Done Waiting.");
        }
开发者ID:jburman,项目名称:razordb,代码行数:18,代码来源:PipelineTests.cs

示例6: PipelineBackpressureTest

        public void PipelineBackpressureTest()
        {
            int finalTotal = 0;

            Pipeline<int> Waiting2Pipeline = new Pipeline<int>((i) => {
                Thread.Sleep(1);
                finalTotal += i;
            },10);
            Pipeline<int> DoublePipeline = new Pipeline<int>((i) => {
                Waiting2Pipeline.Push(i / 2);
            },20);
            Pipeline<int> HalfPipeline = new Pipeline<int>((i) => {
                DoublePipeline.Push(i * 2);
            },5);

            for (int i = 0; i < 200; i++) {
                HalfPipeline.Push(i);
            }

            Console.WriteLine("Done pushing.");
            HalfPipeline.WaitForDrain();
            DoublePipeline.WaitForDrain();
            Waiting2Pipeline.WaitForDrain();
            Console.WriteLine("Max 0: {0} Max 1: {1} Max 2: {2}", HalfPipeline.MaxQueueSize, DoublePipeline.MaxQueueSize, Waiting2Pipeline.MaxQueueSize);
            Console.WriteLine("Done.");
            Assert.AreEqual(19900, finalTotal);
        }
开发者ID:jburman,项目名称:razordb,代码行数:27,代码来源:PipelineTests.cs

示例7: OnErrorTest2

        public void OnErrorTest2()
        {
            Pipeline<int> pipeline = new Pipeline<int>((i) => {
                throw new NotSupportedException();
            });
            Exception error = null;
            pipeline.OnError = delegate(Exception e) {
                error = e;
            };

            pipeline.Push(1);
            pipeline.WaitForDrain();
            Assert.True(error != null && error is NotSupportedException);
        }
开发者ID:jburman,项目名称:razordb,代码行数:14,代码来源:PipelineTests.cs


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