在asp.net中运行方法异步 [英] Run method asynchronously in asp.net

查看:176
本文介绍了在asp.net中运行方法异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有与产生某些文件到服务器的路径的一个按钮的网页。 (它从5至20分钟取某处)。我想创建一个异步的任务,将继续执行用户关闭浏览器后还是一样。是否有可能用asp.net 4和C#这样做吗?

I have a webpage with a button that generates some files to a server path. (It takes somewhere from 5 to 20 minutes). I want to create an async task that will continue executing even after the user closes the browser. Is it possible to do this with asp.net 4 and C#?

推荐答案

您不控制在asp.net应用程序的线程池。你甚至不能保证一个请求,它开始与在同一线程上完成。创建线程使用Web服务器使用相同的应用程序池,最多可以使用所有的请求的线程离开你的Web服务器无法处理请求。

You do not control the thread pool in an asp.net application. You cannot even guarantee that a request will be completed on the same thread that it started with. Creating threads uses the same application pool that the web server uses, and you can use up all the request threads leaving your web server unavailable to process requests.

您应该实现承载WCF服务,您可以从您的Web应用程序中调用Windows服务。在服务可以再火了一个线程来处理长时间运行的过程。在这一过程结束后,您就可以更新状态标志(例如,从的处理的到的完成的),用户可以查看,以确定该文件被处理完毕。

You should implement a windows service that hosts a WCF service that you can call from within your web application. In the service you can then fire off a thread to process the long running process. At the end of that process you can then update a status flag (e.g from Processing to Complete) that the user can view to determine if the files are done processing.

我会建议使用 Topshelf 来实现你的Windows服务,它会为你节省大为头痛。

I would recommend using Topshelf to implement your windows service, it will save you much headache.

这篇关于在asp.net中运行方法异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆