本文整理汇总了C#中Pipeline.OrderedPush方法的典型用法代码示例。如果您正苦于以下问题:C# Pipeline.OrderedPush方法的具体用法?C# Pipeline.OrderedPush怎么用?C# Pipeline.OrderedPush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pipeline
的用法示例。
在下文中一共展示了Pipeline.OrderedPush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}