Pick Activity(Build in Activity Sample)

The Pick activity provides event-based control modeling. It behaves similar to the C# switch statement, which executes only one of the branches in the switchstatement. Unlike the switch statement in which a branch is executed based upon on a value, the Pick activity executes a branch based upon how an activity completes.

This sample prompts a user to type in their name on the console within a given time period. The Pick activity in the sample has two branches that are executed based upon whether the user types in their name within 5 seconds or not. If the user types in their name within 5 seconds, the first branch is executed, which contains a custom ReadLine activity; otherwise the other branch is executed, which contains a Delay activity. Once a user’s name is typed in on the console, the user’s name is printed on the console. If an input is not entered within 5 seconds, the operation is timed out.

 

Pick Activity(Build in Activity Sample)_第1张图片 

here comes the msdn definition of pick activity :

Schedules all child PickBranch activities and cancels all but the first to have its trigger complete.  The PickBranch activity has both a Trigger and an Action; each is an Activity.  When a trigger activity completes, the Pick cancels all its other child activities.  

按我的理解和实际运行的例子告诉我:

这里要理解Schedule这个单词的含义,实际上它会安排所有的PickBranch下的trigger同时运行。每个PickBranch就好象N个人的200米赛道。trigger可以理解为每个人的一个半程目标,也许A的半程目标是50米,B的是75米等等之类的。A,B的速度不敢说是一致的。但是可以肯定是,实际上,第一个跑完半程的人才允许继续跑完他的200米赛道,并且与此同时,会取消其它所有人的200米比赛。 

结合上图的示例来说,右边的Trigger是一个延时,假设是5秒,左边不管他是什么,只要能在5秒之前完成,那么就会完成左边的完整分支执行,否则相反。 

如MSDN所言,的确是很象Switch。个人理解,欢迎指点。谢谢。

 

你可能感兴趣的:(Activity)