简体   繁体   English

ASP.Net MVC 4-一个以上的线程

[英]ASP.Net MVC 4 - more than one thread

处理

I have an MVC 4 application that should do the following: 我有一个MVC 4应用程序,应执行以下操作:

1- Asks user to enter their Email address (Action 1 -> View 1) 1-要求用户输入其电子邮件地址(操作1->视图1)

2- Shows acknowledgement of receiving request (Action 2 -> View 2) - User should be able to close web page here . 2-显示接收请求的确认(动作2->视图2)- 用户应该可以在此处关闭网页

3- Starts long process on server (Action 3) and when finished, notifies user by Email. 3-在服务器上启动长进程(操作3),完成后,通过电子邮件通知用户。

How can I achieve this? 我该如何实现? I will need to create a new thread on Action 2, am I correct? 我需要在操作2上创建一个新线程,对吗?

Thanks! 谢谢!

Consider using task and await included in .net 4.5. 考虑使用task并等待.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 完整的文章可以在这里找到: http : //www.asp.net/mvc/tutorials/mvc-4/using-asynchronous-methods-in-aspnet-mvc-4

I would put a message from Action 2 into a message queue of some sort. 我会将动作2中的消息放入某种消息队列中。 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. 这样,您的Web服务器就可以腾出时间来专注于服务网页和Web服务,而不是为长期运行的任务提供服务。

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

相关问题 在 ASP.NET MVC 中是否可以有多个路由? - Is it possible to have more than one routing in ASP.NET MVC? 如何从一个数据库(ASP.NET MVC)创建多个表? - How to create more than one table from one database (ASP.NET MVC)? 从具有多个参数作为数据的请求处理程序中调用ASP.NET MVC控制器 - Invoking a ASP.NET MVC controller from a request handler with more than one parameter as data Asp.net MVC Nhibernate:不能通过联接视图修改多个基本表 - Asp.net MVC Nhibernate : Can not modify more than one base table through a join view 与Entity Framework ASP.net MVC中的多个表的可选关系 - Optional relationship to more than one table in Entity Framework ASP.net MVC 如何在ASP.NET MVC 3中处理每个键的多个值? - How to deal with more than one value per key in ASP.NET MVC 3? ASP.NET MVC4-用多种方法添加到ViewBag吗? - ASP.NET MVC4 - Adding to ViewBag in more than one method? ASP.Net MVC如何将多个行保存到数据库 - ASP.Net MVC how to save more than one row to data Base 如何使用 asp.net mvc 在您的 DbContext 中使用多个 model? - How to use more than one model in your DbContext using asp.net mvc? 如何在asp.net mvc中使用Linq从数据库中删除多条记录 - how delete more than one record from database using Linq in asp.net mvc
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM