调用NativeActivityContext.ScheduleDelegate的正确方法是什么?
本文关键字:方法 是什么 NativeActivityContext ScheduleDelegate 调用 | 更新日期: 2023-09-27 17:52:35
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返回负值。因为我必须留在执行方法和执行迭代,我认为调用工作流参数的唯一方法是使用NativeActivityContext.ScheduleDelegate。该程序的唯一限制是不使用WorkflowInvoker.Invoke。有人知道怎么用ScheduleDelegate吗?
谢谢,Moiz
我写了一个可能对您有所帮助的示例。参见WF4如何调用子工作流作为XAML