第二次运行子活动

发布于 2024-08-12 18:43:39 字数 595 浏览 9 评论 0原文

我正在尝试使用 WF3.5 编写自定义 CompositeActivity。类似于 WhileActivity 的东西。

问题是,当我想再次执行子活动时(之前通过对 ActivityExecutionContext.CloseActivity() 的最终调用成功),我收到 InvalidOperationException,并显示以下消息:“活动状态必须为‘初始化’才能执行”。

从调试问题来看,子活动的 ExecutionStatus 似乎已关闭,而其 ExecutionResult 则为 Uninitialized。

但是 ActivityExecutionContext.ExecuteActivity 表示“如果状态为 Closed,则 Activity 被初始化并执行”。

那么为什么我会遇到这个异常以及如何避免它?

谢谢, 朱利安

I am trying to write a custom CompositeActivity using WF3.5. Something like a WhileActivity.

The problem is when I want to execute the child activity again (it previously succeeded with a final call to ActivityExecutionContext.CloseActivity()) I get an InvalidOperationException, with this message: "Activity status must be 'Initialized' for executing".

From debugging the problem, it appears that the child activity's ExecutionStatus is Closed and its ExecutionResult is Uninitialized.

But the MSDN doc for ActivityExecutionContext.ExecuteActivity says that "If the status is Closed, the Activity is initialized and executed".

So why am I getting this exception and how can I avoid it?

Thanks,
Julien

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-08-19 18:43:39

我想我找到了答案。复合活动每次想要启动子活动时都需要为子活动创建新的 ActivityExecutionContext。

在新的 ActivityExecutionContext 中执行子 Activity:

ActivityExecutionContext context2 = executionContext.ExecutionContextManager.CreateExecutionContext(a);

// listen for the child's activity completion by implementing IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
context2.Activity.RegisterForStatusChange(Activity.ClosedEvent, this);
context2.ExecuteActivity(context2.Activity);

活动关闭后进行清理:

// get the activity from the ActivityExecutionStatusChangedEventArgs, then...
activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
ActivityExecutionContextManager executionContextManager = executionContext.ExecutionContextManager;

// close the child activity's execution context
executionContextManager.CompleteExecutionContext(executionContextManager.GetExecutionContext(activity));

I think I found the answer. The composite activity needs to create new ActivityExecutionContext for the child activity every time it wants to start the child activity.

Executing the child activity in a new ActivityExecutionContext:

ActivityExecutionContext context2 = executionContext.ExecutionContextManager.CreateExecutionContext(a);

// listen for the child's activity completion by implementing IActivityEventListener<ActivityExecutionStatusChangedEventArgs>
context2.Activity.RegisterForStatusChange(Activity.ClosedEvent, this);
context2.ExecuteActivity(context2.Activity);

Cleaning up after the activity is Closed:

// get the activity from the ActivityExecutionStatusChangedEventArgs, then...
activity.UnregisterForStatusChange(Activity.ClosedEvent, this);
ActivityExecutionContextManager executionContextManager = executionContext.ExecutionContextManager;

// close the child activity's execution context
executionContextManager.CompleteExecutionContext(executionContextManager.GetExecutionContext(activity));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文