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


C# BufferBlock.Fault方法代码示例

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


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

示例1: PropagateFaultTest

		public void PropagateFaultTest ()
		{
			ISourceBlock<int> source = new BufferBlock<int> ();
			var target = new BufferBlock<int> ();
			Assert.IsNotNull (source.LinkTo (target,
				new DataflowLinkOptions { PropagateCompletion = true }));

			Assert.IsFalse (target.Completion.Wait (100));
			var exception = new Exception ();
			source.Fault (exception);

			var ae =
				AssertEx.Throws<AggregateException> (() => source.Completion.Wait (100));
			Assert.AreEqual (exception, ae.Flatten ().InnerException);

			ae = AssertEx.Throws<AggregateException> (() => target.Completion.Wait (100));
			Assert.AreEqual (exception, ae.Flatten ().InnerException);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:18,代码来源:PropagateCompletionTest.cs

示例2: TestLinkTo_PropagateCompletion

        public async Task TestLinkTo_PropagateCompletion()
        {
            IPropagatorBlock<int, int> source;
            ITargetBlock<int> target;

            source = new BufferBlock<int>();
            target = new ActionBlock<int>(i => { });
            source.LinkTo(target, new DataflowLinkOptions { PropagateCompletion = true });
            source.Complete();
            await target.Completion;

            source = new BufferBlock<int>();
            target = new ActionBlock<int>(i => { });
            source.LinkTo(target, new DataflowLinkOptions { PropagateCompletion = true });
            source.Fault(new InvalidOperationException());
            await Assert.ThrowsAsync<AggregateException>(() => target.Completion);
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:17,代码来源:DataflowBlockExtensionTests.cs

示例3: TestLinkTo_DoubleLinking

        public async Task TestLinkTo_DoubleLinking()
        {
            foreach (bool greedy in DataflowTestHelpers.BooleanValues)
            foreach (bool append in DataflowTestHelpers.BooleanValues)
            {
                var source1 = new BufferBlock<int>();
                var source2 = new BufferBlock<int>();
                var jb = new JoinBlock<int, int>(new GroupingDataflowBlockOptions { MaxNumberOfGroups = 1, Greedy = greedy });

                var ignored = source1.Completion.ContinueWith(_ => jb.Target1.Complete(), TaskScheduler.Default);
                ignored = source2.Completion.ContinueWith(_ => jb.Target2.Complete(), TaskScheduler.Default);

                using (source1.LinkTo(jb.Target1))
                {
                    source1.LinkTo(jb.Target1, new DataflowLinkOptions { Append = append }); // force NopLinkPropagator creation
                }
                using (source2.LinkTo(jb.Target2))
                {
                    source2.LinkTo(jb.Target2, new DataflowLinkOptions { Append = append }); // force NopLinkPropagator creation
                }

                source1.Post(42);
                source2.Post(43);

                source1.Complete();
                source2.Complete();

                var tuple = jb.Receive();
                Assert.Equal(expected: 42, actual: tuple.Item1);
                Assert.Equal(expected: 43, actual: tuple.Item2);
            }

            ITargetBlock<int> target = new ActionBlock<int>(i => { });
            ISourceBlock<int> source = new BufferBlock<int>();
            using (source.LinkTo(target))
            {
                source.LinkTo(target, new DataflowLinkOptions { PropagateCompletion = true });
                source.LinkTo(target, new DataflowLinkOptions { PropagateCompletion = true }, f => false);
            }
            source.Fault(new FormatException());
            await Assert.ThrowsAsync<AggregateException>(() => target.Completion);
        }
开发者ID:gitter-badger,项目名称:corefx,代码行数:42,代码来源:DataflowBlockExtensionTests.cs

示例4: TestFaultyTarget

        public async Task TestFaultyTarget()
        {
            ISourceBlock<int> bb = new BufferBlock<int>();
            bb.Fault(new InvalidCastException());
            await Assert.ThrowsAsync<InvalidCastException>(() => bb.Completion);

            Assert.Throws<FormatException>(() => {
                bb.LinkTo(new DelegatePropagator<int, int>
                {
                    FaultDelegate = delegate { throw new FormatException(); }
                }, new DataflowLinkOptions { PropagateCompletion = true });
            });
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:13,代码来源:BufferBlockTests.cs


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