当前位置: 首页>>代码示例>>C#>>正文


C# Task.Where方法代码示例

本文整理汇总了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));
        }
开发者ID:CRogers,项目名称:KinectGroupPractical,代码行数:29,代码来源:Robot.cs

示例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);
		}
开发者ID:artikh,项目名称:CouchDude.Bootstrapper,代码行数:6,代码来源:CouchDBReplicator.cs


注:本文中的System.Threading.Tasks.Task.Where方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。