[英]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.