递归调用 Windows 工作流
我有一个工作流程,在某个时刻需要递归触发。
我似乎不知道该怎么做。
我尝试了以下代码,但上下文最终为空?
private void codeTriggerChildren_ExecuteCode(object sender, EventArgs e)
{
ActivityExecutionContext context = sender as ActivityExecutionContext;
//context is null here?!
IStartWorkflow aWorkflow = context.GetService(typeof(ApprovalFlow)) as IStartWorkflow;
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Parm1", "foo");
parameters.Add("Parm2", "bar");
Guid guid = aWorkflow.StartWorkflow(typeof(ApprovalFlow), parameters);
}
I have a workflow, that at a certain point, needs to be triggered recursively.
I can't seem to figure out how to do this.
I tried the following code but context ends up being null??
private void codeTriggerChildren_ExecuteCode(object sender, EventArgs e)
{
ActivityExecutionContext context = sender as ActivityExecutionContext;
//context is null here?!
IStartWorkflow aWorkflow = context.GetService(typeof(ApprovalFlow)) as IStartWorkflow;
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Parm1", "foo");
parameters.Add("Parm2", "bar");
Guid guid = aWorkflow.StartWorkflow(typeof(ApprovalFlow), parameters);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的主要问题是,本例中的发送者是 CodeActivity,而不是 ActivityExecutionContext。所以这段代码在第一个障碍处就失败了。
下面是一个自定义活动的示例,可以执行您想要的操作:-
请注意,GetService 获取
IStartWorkflow
类型。Primarily the problem here is that the sender in this case is a
CodeActivity
not anActivityExecutionContext
. So this code fails at the first hurdle.Here is an example of custom activity that can do what you are after:-
Note that the GetService gets type of
IStartWorkflow
.您的发送者的类型为 CodeActivity 而不是 ActivityExecutionContext。您需要创建一个自定义活动并重写 Execute 方法,该方法将向您传递 ActivityExecutionContext。
Your sender is of type CodeActivity not ActivityExecutionContext. You need to create a custom activity and override the Execute method which will pass you a ActivityExecutionContext.