本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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 });
});
}