zoukankan      html  css  js  c++  java
  • WF4.0 Beta1 CancellationScope 取消容器

    WF4.0 Beta1 CancellationScope 取消容器

     

    在WF4中,可以使用[Parallel] 并行执行多条分支,当[Parallel]中的所有分支都执行完成后,[Parallel]结束.

    在WF4中,可以使用[Pick]实现多条等待分支的单线执行,当一条分支被触发后,其它分支就不会被触发了,当触发的分支完成后,[Pick]结束

    但有时我们会的这样一种需求,我们需要并行执行多条分支,当并行分支中的一条或几条分支满足指定条件时,其它正在执行的分支就不执了.同时,为了保证数据的完整性,我们需要在那些可能要取消的分支中余留一组代码.这组代码用于在该分支被取消后做一些收尾工做.

    CancellationScope 取消容器

    类名: System.Activities.Statements.CancellationScope

    基类: NativeActivity

    文件: System.Activities.dll

    类型: sealed

    说明: 1. 在WF4中,可以使用[Parallel] 并行执行多条分支,当[Parallel]中的所有分支都执行完成后,[Parallel]结束.

    可以使用[Pick]实现多条等待分支的单线执行,当一条分支被触发后,其它分支就不会被触发了,当触发的分支完成后,[Pick]结束

    但有时我们会的这样一种需求,我们需要并行执行多条分支,当并行分支中的一条或几条分支满足指定条件时,其它正在执行的分支就不执了.同时,为了保证数据的完整性,我们需要在那些可能要取消的分支中余留一组代码.这组代码用于在该分支被取消后做一些收尾工做.

    2. [CancellationScope]由[Body]与 [CancelHandler] 两部分组成,[Body]为正常执行路径, 如果取消执行会调用 [CancelHandler]中的内容

    3. 可以在[Parallel]容器中使用[CancellationScope],当[Parallel]的[CompletionCondition]属性为[True]时,[Parallel]容器会在其内部[CancellationScope]容器执行完成后,结束其它正在执行的并行分支.如果其它正在执行的并行分支是[CancellationScope],则会调用该[CancellationScope]的[CancelHandler]

     

    流程

    <p:Activity

    mc:Ignorable=""

    x:Class="WorkflowConsoleApplication4.Sequence1" xmlns="http://schemas.microsoft.com/netfx/2009/xaml/activities/design" xmlns:__Sequence1="clr-namespace:WorkflowConsoleApplication4;" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="http://schemas.microsoft.com/netfx/2009/xaml/activities" xmlns:sad="clr-namespace:System.Activities.Debugger;assembly=System.Activities" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <p:Sequence>

    <p:Parallel CompletionCondition="[True]">

    <p:CancellationScope DisplayName="CancellationScope:A">

    <p:CancellationScope.CancelHandler>

    <p:WriteLine DisplayName="WriteLine:Cancel A">["Cancel A"]</p:WriteLine>

    </p:CancellationScope.CancelHandler>

    <p:Sequence>

    <p:WriteLine DisplayName="WriteLine:begin A">["begin A"]</p:WriteLine>

    <p:Delay DisplayName="Delay:5">[New TimeSpan(0, 0, 5)]</p:Delay>

    <p:WriteLine DisplayName="WriteLine:end A">["end A"]</p:WriteLine>

    </p:Sequence>

    </p:CancellationScope>

    <p:CancellationScope DisplayName="CancellationScope:B">

    <p:CancellationScope.CancelHandler>

    <p:WriteLine DisplayName="WriteLine:Cancel B">["Cancel B"]</p:WriteLine>

    </p:CancellationScope.CancelHandler>

    <p:Sequence>

    <p:WriteLine DisplayName="WriteLine:begin B">["begin B"]</p:WriteLine>

    <p:Delay DisplayName="Delay:10">[New TimeSpan(0, 0, 10)]</p:Delay>

    <p:WriteLine DisplayName="WriteLine:end B">["end B"]</p:WriteLine>

    </p:Sequence>

    </p:CancellationScope>

    <p:CancellationScope DisplayName="CancellationScope:C">

    <p:CancellationScope.CancelHandler>

    <p:WriteLine DisplayName="WriteLine:Cancel C">["Cancel C"]</p:WriteLine>

    </p:CancellationScope.CancelHandler>

    <p:Sequence>

    <p:WriteLine DisplayName="WriteLine:begin C">["begin C"]</p:WriteLine>

    <p:Delay DisplayName="Delay:3">[New TimeSpan(0, 0, 3)]</p:Delay>

    <p:WriteLine DisplayName="WriteLine:end C">["end C"]</p:WriteLine>

    </p:Sequence>

    </p:CancellationScope>

    <p:Sequence DisplayName="Sequence:D">

    <p:WriteLine DisplayName="WriteLine:begin D">["begin D"]</p:WriteLine>

    <p:Delay DisplayName="Delay:8">[New TimeSpan(0, 0, 8)]</p:Delay>

    <p:WriteLine DisplayName="WriteLine:end D">["end D"]</p:WriteLine>

    </p:Sequence>

    </p:Parallel>

    <p:WriteLine DisplayName="WriteLine:wxwinter">["wxwinter"]</p:WriteLine>

    </p:Sequence>

    </p:Activity>

    宿主

    WorkflowInstance myInstance = new WorkflowInstance(new Sequence1());

    myInstance.OnCompleted = delegate(WorkflowCompletedEventArgs e) { System.Console.WriteLine("Completed "); };

     

    myInstance.Run();

     

    System.Console.Read();

    结果

    [Parallel][CompletionCondition]属性为[False]

    结果

    [Parallel][CompletionCondition]属性为[False]

     

     

  • 相关阅读:
    两台Mysql数据库数据同步实现
    利用Python读取外部数据文件
    在Python应用中使用MongoDB
    使用python语言操作MongoDB
    windows下Graphviz安装及入门教程
    【Machine Learning】决策树案例:基于python的商品购买能力预测系统
    Python数据可视化-seaborn
    np.tile 函数使用
    Python机器学习库scikit-learn实践
    基于C#net4.5websocket客户端与服务端
  • 原文地址:https://www.cnblogs.com/foundation/p/1507391.html
Copyright © 2011-2022 走看看