本文整理汇总了C#中System.Threading.Tasks.Task.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Where方法的具体用法?C# Task.Where怎么用?C# Task.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Task
的用法示例。
在下文中一共展示了Task.Where方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Robot
public Robot(JointMotorConfig jmc)
{
JointMotorConfig = jmc;
// Make bluetooth connections - if it is -1 don't make connection
nxtBricks = new NxtBrick[jmc.ComPorts.Length];
var connectTasks = new Task<NxtBrick>[jmc.ComPorts.Length];
for (int i = 0; i < jmc.ComPorts.Length; i++) {
var comPort = jmc.ComPorts[i];
if (comPort >= 0) {
int j = i; // Prevent access to modified closure
connectTasks[i] = new Task<NxtBrick>(() => ConnectBrick(j, jmc.LinkTypes[j], comPort));
connectTasks[i].Start();
}
}
Task.WaitAll(connectTasks.Where(a => a != null).ToArray());
Logger.Log("Connected all motors");
for (int i = 0; i < connectTasks.Length; i++) {
nxtBricks[i] = connectTasks[i] == null ? null : connectTasks[i].Result;
}
// Add joints
LeftArm = new Arm("Left", AddMotorToNxt(jmc.LeftShoulderAlong), AddMotorToNxt(jmc.LeftShoulderOut), AddMotorToNxt(jmc.LeftElbowAlong), AddMotorToNxt(jmc.LeftElbowOut));
RightArm = new Arm("Right", AddMotorToNxt(jmc.RightShoulderAlong), AddMotorToNxt(jmc.RightShoulderOut), AddMotorToNxt(jmc.RightElbowAlong), AddMotorToNxt(jmc.RightElbowOut));
}
示例2: ThrowAggregateIfFaulted
private static void ThrowAggregateIfFaulted(Task<DocumentInfo>[] tasks)
{
var exceptions = tasks.Where<Task>(dt => dt.IsFaulted).Select(dt => dt.Exception).ToArray();
if (exceptions.Length > 0)
throw new AggregateException(exceptions);
}