如何异步调用另一个控制器操作?
我正在使用 ActionMailer.net 从我的 MVC 网站发送电子邮件,问题是发送电子邮件有时需要几秒钟,这会延迟我的 ajax 调用。
我尝试使用DeliverAsync(),但同样的延迟仍然存在,我像这样调用ActionMailer控制器操作:
new EmailController().EntryEmail(CurrentUser, CurrentUser, postText).DeliverAsync();
所以我的问题是,有没有办法调用相同的操作,但在另一个线程或异步。
备注:
我试图让 ActionMailer 控制器继承自 AsyncController
但不能,因为它已经从另一个类继承。
另外供参考,我之前问过这个问题:是像这样从另一个线程发送电子邮件可以吗?
I am using ActionMailer.net to send emails from my MVC website, the problem is that sending an email some times takes few seconds, and this delay my ajax calls.
I tried to use DeliverAsync()
but the same delay is still there, I call the ActionMailer controller action like this:
new EmailController().EntryEmail(CurrentUser, CurrentUser, postText).DeliverAsync();
So my question is, is there a way to call the same Action but in another thread or async.
Notes:
I tried to make the ActionMailer controller inherits from AsyncController
but couldn't because it is already inheriting from another class.
Also for reference I asked this question before: Is it fine to send email from another thread like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不创建一个继承自 AsyncController 的新基类?
对于简单的“即发即忘”,您可以使用 ThreadPool.QueueUserWorkItem 。
就我个人而言,我更喜欢对电子邮件进行排队,并让一个单独的后台线程处理队列。这可以像数据库中的“电子邮件”表和 System.Threading.Timer 一样简单
Why not create a new base class that inherits from AsyncController?
For a simple fire and forget you can use
ThreadPool.QueueUserWorkItem
.Personally, I prefer to queue emails and have a separate background thread process the queue. This can be as simple as an "Email" table in a database and a
System.Threading.Timer