【发布时间】:2013-09-03 08:32:23
【问题描述】:
我在一个 ASP.NET 站点中有一个 Web 方法,它可以运行很长时间并消耗大量 CPU 容量。也有可能,在返回请求之前,用户可以从站点触发带有其他或更多参数的新请求。在客户端执行中止:
if (xhrConfigurate != null) {
xhrConfigurate.abort();
}
当然,abort 不会停止服务器上的计算。我坚持,这没关系,服务器会做它必须做的,但不会返回旧请求的结果。但似乎在某些情况下,服务器无法及时处理所有请求。 这就是为什么我还想在用户启动新请求时终止旧请求。我用 scriptmanager 找到了一些解决方案,但想避免使用它。
由于 webmethod 本身是一个异步线程,我不能获取这个线程的一个实例,将它存储在某个字典中,在那里我可以中止对用户的旧的未完成请求并在完成时删除一个请求?
<WebMethod> Public Shared Function myRequest(ByVal params As String) As String
'Get the dictionary with requests
'Test the dictionary on old unfinsihed request for the user, if there is one: abort
'Add this request to the dictionary
'Do work...
'If work finsihed: remove this request from dictionary
Return result
End Sub
【问题讨论】: