工作流程中止
我正在开发一个 Asp .net 应用程序,并且正在使用 Windows 工作流基础 4。当我终止工作流时,我想使用以下代码导出原因
app.Aborted = delegate(WorkflowApplicationAbortedEventArgs o)
{
HttpContext.Current.Response.Write("Exception:" + o.Reason.GetType().FullName + o.Reason.Message);
syncEvent.Set();
};
,但我认为它不起作用,因为工作流没有 HttpContext。有什么想法如何导出它吗?
I am working on an Asp .net application and i am using Windows workflow foundation 4. When i terminate the workflow i want to export the reason with the following code
app.Aborted = delegate(WorkflowApplicationAbortedEventArgs o)
{
HttpContext.Current.Response.Write("Exception:" + o.Reason.GetType().FullName + o.Reason.Message);
syncEvent.Set();
};
But i think it doesn't works because the workflow doesnt have HttpContext. Any ideas how can i export it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为最简单的方法是将 WorkflowApplication 和 HttpContext 包装在同一个类中,例如:
I think the simplest way is to wrap the WorkflowApplication and HttpContext in the same class, for example:
问题在于 HttpContext.Current 是一个线程静态字段,其作用域为当前执行 ASP.NET 请求的线程,而 WorkflowApplication 在后台 ThreadPool 线程上运行工作流和回调。
事实上,您想要将错误写回响应流,这表明您正在使用一个短时间运行的工作流程。在这种情况下,使用 WorkflowInvoker 来运行工作流要容易得多,因为不涉及后台线程。
如果您更喜欢 WorkflowApplication,那么我建议您查看 SynchronizationContext 属性并进行设置,以便大多数回调将返回到原始线程。
The problem is that HttpContext.Current is a thread static field scoped to the current thread executing the ASP.NET request while the WorkflowApplication runs the workflow and the callbacks on a background ThreadPool thread.
The fact that you want to write the error back to the response stream suggest you are working with a short running workflow here. In that case it is much easier to use a WorkflowInvoker to run the workflow as there are no background threads involved.
If you perfer the WorkflowApplication than I suggest looking into the SynchronizationContext property and setting that so most callbacks will be martialled back onto the original thread.