RonaDona
RonaDona

Reputation: 932

ASP.Net MVC 4 - more than one thread

Process

I have an MVC 4 application that should do the following:

1- Asks user to enter their Email address (Action 1 -> View 1)

2- Shows acknowledgement of receiving request (Action 2 -> View 2) - User should be able to close web page here.

3- Starts long process on server (Action 3) and when finished, notifies user by Email.

How can I achieve this? I will need to create a new thread on Action 2, am I correct?

Thanks!

Upvotes: 0

Views: 181

Answers (2)

Mike Parkhill
Mike Parkhill

Reputation: 5551

I would put a message from Action 2 into a message queue of some sort. I'd then have a background process (ideally on a different server) process the message and send the email. That way your web server is freed up to focus on serving web pages and web services and not servicing long running tasks.

Upvotes: 2

Mike Beeler
Mike Beeler

Reputation: 4101

Consider using task and await included in .net 4.5. Async method example shown:

public async Task<List<Gizmo>> GetGizmosAsync()
{
    var uri = Util.getServiceUri("Gizmos");
    using (HttpClient httpClient = new HttpClient())
    {
        var response = await httpClient.GetAsync(uri);
        return (await response.Content.ReadAsAsync<List<Gizmo>>());
    }
}

Complete article can be found here: http://www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4

Upvotes: 3

Related Questions