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調用具有參數的工作流的唯一方法是使用NativeActivityContext.ScheduleDelegate。程序中唯一的限制是不使用WorkflowInvoker.Invoke。有人知道如何使用ScheduleDelegate嗎?WF4 - 調用NativeActivityContext.ScheduleDelegate的正確方法是什麼?
謝謝,Moiz
不太確定你在這裏試圖做什麼。您正在調用沒有參數的DynamicActivity,只是帶有輸入參數的變量。 – Maurice 2011-04-26 06:52:39
莫里斯,我更新了我的問題。如果你知道答案,請發帖。 – Moiz 2011-04-27 23:17:21