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