工作流程中止

发布于 2024-11-30 17:06:30 字数 380 浏览 1 评论 0原文

我正在开发一个 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 技术交流群。

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

发布评论

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

评论(2

深居我梦 2024-12-07 17:06:30

我认为最简单的方法是将 WorkflowApplication 和 HttpContext 包装在同一个类中,例如:


class WorkflowAppAdapter
    {
        private HttpContext m_Context;
        private WorkflowApplication m_WorkflowApp;

        public WorkflowAppAdapter(WorkflowApplication app, HttpContext context)
        {
            m_Context = context;
            m_WorkflowApp = app;

            app.Completed =
                (e) =>
                {
                    Debug.WriteLine(m_Context.Request.Browser.Browser);

                };
        }

        public void Run()
        {
            m_WorkflowApp.Run();
        }
    }

I think the simplest way is to wrap the WorkflowApplication and HttpContext in the same class, for example:


class WorkflowAppAdapter
    {
        private HttpContext m_Context;
        private WorkflowApplication m_WorkflowApp;

        public WorkflowAppAdapter(WorkflowApplication app, HttpContext context)
        {
            m_Context = context;
            m_WorkflowApp = app;

            app.Completed =
                (e) =>
                {
                    Debug.WriteLine(m_Context.Request.Browser.Browser);

                };
        }

        public void Run()
        {
            m_WorkflowApp.Run();
        }
    }
小草泠泠 2024-12-07 17:06:30

问题在于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文