是否有可能继续之前慢速服务器端工作(例如日志记录)返回ASP页 [英] Is it possible to return an ASP page before continuing slow server side work (eg logging)
问题描述
是否有可能返回页面响应用户,你完成你所有的服务器端工作过吗?
Is it possible to return the page response to the user, before you've finished all your server side work?
也就是说,我有没有数据库便宜的托管帐户,但我想记录某个事件,通过调用我的其他,更昂贵的托管帐户(即一个非常缓慢的日志操作)web服务
Ie, I've got a cheap hosting account with No database, but I'd like to log a certain event, by calling a webservice on my other, more expensive hosting account (ie, a very slow logging operation)
我真的不希望用户必须等待这种缓慢日志操作来完成他们的页面呈现之前。
I don't really want the user to have to wait for this slow logging operation to complete before their page is rendered.
我会需要旋转了一个新的线程,或者使异步调用?或者是有可能返回的页面,然后继续在同一个线程/ code愉快地工作吗?
Would I need to spin up a new thread, or make an asynchronous call? Or is it possible to return the page, and then continue working happily in the same thread/code?
使用ASP.Net(web表单)C#.NET 2.0等。
Using ASP.Net (webforms) C# .Net 2.0 etc.
推荐答案
您可能会需要第二个线程。一个简单的办法是使用线程池
,但在一个更复杂的设置生产者/消费者队列将工作做好。
You would probably need a second thread. An easy option would be to use the ThreadPool
, but in a more sophisticated setup a producer/consumer queue would work well.
在最简单的:
ThreadPool.QueueUserWorkItem(delegate {
DoLogging(state details);
});
这篇关于是否有可能继续之前慢速服务器端工作(例如日志记录)返回ASP页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!