簡體   English   中英

WF4-調用NativeActivityContext.ScheduleDelegate的正確方法是什么?

[英]WF4 - what is the right way of calling NativeActivityContext.ScheduleDelegate?

public class NativeActivity1 : NativeActivity
{
    public NativeActivity1()
    {
        var myDynamicActivity = ActivityXamlServices.Load(@"C:\WorkflowConsoleApplication1\WorkflowConsoleApplication1\Workflow1.xaml") as DynamicActivity;
        var argInt32 = new InOutArgument<int>();

        this.ChildActivity = new DynamicActivity
        {
            Properties = { new DynamicActivityProperty() { Name="argInt32", Type=typeof(InOutArgument<int>), Value=argInt32 }, },
            Implementation = () => new Sequence
            {
                Activities =
                {
                    myDynamicActivity,
                    new WriteLine { Text = new InArgument<string>(ctx => argInt32.Get(ctx).ToString()) }
                }
            }
        };
    }
    public DynamicActivity ChildActivity { get; set; }
    protected override void Execute(NativeActivityContext context)
    {
        var parameter = 10;
        while (0 < parameter--)
        {
            var activityInstance = context.ScheduleDelegate(
                new ActivityAction { Handler = this.ChildActivity }
                , new Dictionary<string, object> { { "argInt32", parameter } }
                , (activityContext, completedInstance, outArguments) =>
                {
                    Console.WriteLine("Output:" + outArguments["argInt32"].ToString());
                }, (faultContext, propagatedException, propagatedFrom) =>
                {
                    Console.WriteLine("Fault");
                });
        }
    }
}

    class Program
    {
        static void Main(string[] args)
        {
            WorkflowInvoker.Invoke(new NativeActivity1());
            Console.WriteLine("Press any key to end the process ...");
            Console.ReadLine();
        }
    }

我有一個while循環,它使迭代次數從1到10。每個遞增的數字都傳遞給工作流,並且工作流假定通過乘以-1返回負值。 由於我必須留在Execute方法中並執行迭代,因此我認為使用參數調用工作流的唯一方法是使用NativeActivityContext.ScheduleDelegate。 程序中的唯一限制是不要使用WorkflowInvoker.Invoke。 有人知道如何使用ScheduleDelegate嗎?

謝謝,Moiz

我寫了一個樣本可能會對您有所幫助。 請參閱WF4如何將子工作流作為XAML調用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM