简体   繁体   中英

How to call another controller action async?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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