问题描述
在我们的网络应用程序中,用户可以使需要大量的数据库表的更新的改变。加载时间为所有可长达30秒。我不想让用户等待,要导航到另一个页面之前完成。
In our web application, a user can make a change that requires a lot of database tables to update. The load time for all that can be up to 30 seconds. I don't want the user to wait for that to complete before navigating to another page.
我已经把长期运行的code对自己的页面(例如,updateinfo.aspx),并尝试了一些解决方案,其中包括jQuery的AJAX调用updateinfo.aspx或加载图像文件所谓的updateinfo.aspx。在任何情况下,我不能从拉开序幕的AJAX调用另一个HTML网页,而updateinfo.aspx正在执行原来的HTML页面浏览。 Chrome浏览器说,要求updateinfo.aspx正在等待。当我点击一个链接,导航离开原来的HTML页面,我们正在等待example.org ......直到AJAX页面完成,那么请求导航到下一个HTML页面遵循通过和新的一页负荷。
I've put the long-running code on its own page (say, "updateinfo.aspx") and tried a few solutions, including jQuery AJAX calls to "updateinfo.aspx" or loading an image file that calls "updateinfo.aspx". In all cases, I cannot navigate from the original HTML page that kicked off the AJAX call to another HTML page while "updateinfo.aspx" is executing. Chrome says that the request to "updateinfo.aspx" is pending. When I click on a link to navigate away from original HTML page, we're "Waiting for example.org..." until the AJAX page is finished, then the request to navigate to the next HTML page follows through and the new page loads.
所以,这违背把长期运行code到AJAX页面的目的。用户的页面快速渲染,但他们不能转到了另一页,直到AJAX页面完成后继续他们的一天。我不关心AJAX页面的输出。
So, this defeats the purpose of putting the long-running code into an AJAX page. The user's page renders quickly, but they cannot continue about their day by navigating to another page until the AJAX page is finished. I don't care about the output of the AJAX page.
有什么想法?
推荐答案
您真的不应该在网页上下文中执行一个长期运行的进程;在HTTP请求/响应模型是不利于该概念,当客户端应用程序是网页浏览器。这是一个场景我不得不处理若干倍;你可以: -
You shouldn't really execute a long-running process in a web page context; the HTTP Request/Response model is not favourable to that concept when the client application is a web browser. This is a scenario I have had to address a number of times; you could: -
- 使用MSMQ;提交一个消息给一个包含操作细节队列要执行,或者
- 写操作的细节要执行一个作业表
您可以再创建一个Windows服务从队列中读取消息/从表中的时间拉未处理的项目之一,并执行长时间运行的操作。
You can then create a Windows Service to read messages from the queue/pull un-processed items one at a time from the table, and perform the long-running operation.
在最近的项目中,我不得不这样做,从内存中,我创建了一个用户控件,在头(即在母版)坐在其中通过jQuery的Ajax每15秒一次的数据库表轮询来检测时,工作是完成,并显示一个弹出来指示作业结束用户。
In the most recent project I had to do this, from memory, I created a usercontrol that sat in the header (i.e. in the masterpage) which polled the database table via jQuery Ajax once every 15 seconds to detect when the job was completed, and show a popup to the user indicating the job was finished.
我可以尝试,并挖掘出一些实例的地方,但这些是主要的运动部件,这是否帮助呢?
I can try and dig out some examples somewhere but those are the main moving parts, does that help at all ?
这篇关于启动一个长期运行的进程异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!