的Application_Error处理器没有发射时使用preFIX异步 [英] Application_Error handler isn't fired when use prefix async

查看:114
本文介绍了的Application_Error处理器没有发射时使用preFIX异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做出的Application_Error处理程序的异步调用。所以我定义这个处理器与异步关键字,但它不是射击例外。

I have to make an asynchronous call in Application_Error handler. So I've defined this handler with async keyword but it isn't fired on exceptions.

    protected async void Application_Error(object sender, EventArgs e)
    {
        ...

        await DoAsyncCall();

        ...
    }

当我删除异步关键字的处理程序被激活。

The handler is fired when I remove async keyword.

顺便说一句,我已经累到异步关键字添加到的Application_Start处理程序,它工作正常。

BTW, I've tired to add async keyword to Application_Start handler and it works fine.

我怎样才能让的Application_Error异步?或者,我该怎么做,而不异步关键字异步调用?

How can I make Application_Error async? Or how can I make asynchronous calls without async keyword?

推荐答案

这是您发布的解决方案使用Task.Run。我认为这意味着你将有一个线程等待异步任务运行和第二个线程执行任务。这可能意味着你最终使用两个线程。

The solution that you posted uses Task.Run. What I think this means is that you will have one thread waiting for the async task to run and a second thread executing the task. This may mean that you end up using two threads.

我也有类似的问题,但通过使用Server.TransferRequest功能,启动新的异步请求,回答了这个问题。然后我做了以下要求所有的处理。通过经由TransferRequest的报头参数传递的所有数据,我只使用一个线程异步错误控制器。请参阅<一href="http://stackoverflow.com/questions/27584427/asynchronous-error-controller-in-asp-net-mvc/27586322#27586322">Asynchronous在ASP.NET MVC 的错误控制器。

I had a similar question but answered it by using the Server.TransferRequest function to initiate a new async request. I then did all the processing in the following request. By passing all the data via the header parameter of TransferRequest, I had an async error controller using only one thread. See Asynchronous error controller in ASP.NET MVC.

希望这有助于其他人有这个问题。

Hope this helps other people with this issue.

这篇关于的Application_Error处理器没有发射时使用preFIX异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆