我需要以异步模式执行方法。我已经尝试创建委托,但会话在请求完成后被销毁。此功能需要在此之后继续运行,并且能够使用System.Web.HttpContext.Current.Session
。
是否有一种解决方法可以允许异步运行的方法在请求完成后继续执行?
感谢。
答案 0 :(得分:0)
您可以使用委托(例如使用ThreadPool.QueueUserWorkItem
)但您需要获取对委托之外的HttpSessionStateBase
的引用:
HttpSessionStateBase session = Session;
ThreadPool.QueueUserWorkItem(delegate
{
// You can access session variable here
...
});
在您持有参考资料之前,会话不会被销毁。这里有一个简单的示例:Reporting server side operation progress with jQuery UI Progressbar。