For example, there is a Register button, when the button is clicked, it will send an ajax request to the Action Register to do the database processing and then send verification email.
$.ajax({
url: "/Register",
type: 'POST',
error: function(xhr) {},
success: function(data) {
//after success, change the button color
}
});
[HttpPost]
public ActionResult Register() {
//database processing
......
//send email
//(this step takes long period of time, the button wait for long time to change the color, how can i solve this issue?)
}
when you call a long processing operation from a web page you so not want to wait for it to finish. so what you do is add the long processing tasks to a queue and return. you can use something like MSMQ or you can build simple queue mechanism yourself, i.e. insert a record for the email you want to send in a table and then have some other process look at that table and send the emails…