简体   繁体   English

ASP.NET中的SendAsync(异步电子邮件)和事件处理程序/生命周期?

[英]SendAsync (async email) and event handlers / lifecycle in ASP.NET?

One thing I don't understand with sending Async emails from ASP.NET page is when we call SendAsync it should be executed on a separate thread so our page can continue its execution flow and finish its response no matter how long the sending will take. 从ASP.NET页面发送Async电子邮件我不明白的一件事是,当我们调用SendAsync时,它应该在一个单独的线程上执行,这样我们的页面就可以继续执行流程并完成响应,无论发送多长时间。

  1. How then we can call method on the same page using SendCompletedEventHandler ? 那么我们如何使用SendCompletedEventHandler在同一页面SendCompletedEventHandler调用方法? The page object might not exist by that time and in this forum there are examples that people doing that. 到那时页面对象可能不存在,在这个论坛中有人们这样做的例子。

  2. My expectation was that I can have separate class which might have static method which I will execute on SendCompletedEventHandler and this way we can report possible errors. 我的期望是我可以有单独的类,可能有静态方法,我将在SendCompletedEventHandler执行,这样我们就可以报告可能的错误。 However when I'm raising exception in there the exception comes as part of Page Response. 但是,当我在那里引发异常时,异常作为页面响应的一部分出现。 So for me it looks as SendAsync works on the same thread, page waites for it to be executed and comes back with information on any errors raised by it. 所以对我而言,它看起来SendAsync在同一个线程上运行,页面等待它执行,并返回有关它引发的任何错误的信息。

Is it how it should be? 它应该是怎么回事? So what is meaning of the Async then? 那么Async的含义是什么呢?

Completely confused... Can anyone help? 完全糊涂......任何人都可以帮忙吗?

UPDATE: Found a post which helped me a lot HERE IS THE LINK 更新:找到一个帮助我很多的帖子这里是链接

Because the handler is static, it doesn't require the page object to still exist because it doesn't use or depend on object state. 因为处理程序是静态的,所以它不需要页面对象仍然存在,因为它不使用或依赖于对象状态。 When the callbackhandler needs to be called, the method can be invoked with no fear that the original object doesn't exist. 当需要调用callbackhandler时,可以调用该方法,而不必担心原始对象不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM