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