本文整理汇总了C#中BlockingCollection.Select方法的典型用法代码示例。如果您正苦于以下问题:C# BlockingCollection.Select方法的具体用法?C# BlockingCollection.Select怎么用?C# BlockingCollection.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BlockingCollection
的用法示例。
在下文中一共展示了BlockingCollection.Select方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NumberOfResultsIsConsistent
public void NumberOfResultsIsConsistent(ViewDefinition defn)
{
const int cyclesCount = 5;
using (var remoteViewClient = Context.ViewProcessor.CreateClient())
using (var mre = new ManualResetEvent(false))
{
var cycles = new BlockingCollection<IEngineResourceReference<IViewCycle>>();
var listener = new EventViewResultListener();
listener.ProcessCompleted += delegate { mre.Set(); };
listener.ViewDefinitionCompilationFailed += delegate { mre.Set(); };
listener.CycleExecutionFailed += delegate { mre.Set(); };
listener.CycleCompleted += (sender, e) =>
{
cycles.Add(remoteViewClient.CreateCycleReference(e.FullResult.ViewCycleId));
remoteViewClient.TriggerCycle();
};
remoteViewClient.SetResultListener(listener);
remoteViewClient.SetViewCycleAccessSupported(true);
var sequence = ArbitraryViewCycleExecutionSequence.Create(Enumerable.Range(0, cyclesCount).Select(i => DateTimeOffset.Now + TimeSpan.FromHours(i)));
var options = new ExecutionOptions(sequence, ViewExecutionFlags.TriggersEnabled | ViewExecutionFlags.AwaitMarketData, null, new ViewCycleExecutionOptions(default(DateTimeOffset), ExecutionOptions.GetDefaultMarketDataSpec()));
remoteViewClient.AttachToViewProcess(defn.UniqueID, options);
TimeSpan timeout = TimeSpan.FromMinutes(5);
if (! mre.WaitOne(timeout))
{
throw new TimeoutException(string.Format("Failed to get result in {0}", timeout));
}
Assert.Equal(cyclesCount, cycles.Count);
var specs = cycles.Select(GetAllSpecs).ToList();
var inconsistent = specs.Zip(specs.Skip(1), Tuple.Create).SelectMany(
t =>
{
var diff = new HashSet<Tuple<string, ValueSpecification>>(t.Item1);
diff.SymmetricExceptWith(t.Item2);
return diff;
}).Distinct();
if (inconsistent.Any())
{
var counts = string.Join(",", specs.Select(c => c.Count.ToString()));
var inconsistentStrings = specs.Select(s => string.Join(",", s.Where(x => inconsistent.Contains(x)).Select(x => x.ToString())));
string inconsistentString = string.Join(Environment.NewLine, inconsistentStrings);
throw new Exception(string.Format("Inconsistent number of results for {0} {1}: {2}", defn.Name, counts, inconsistentString));
}
}
}