【发布时间】:2012-02-01 21:37:06
【问题描述】:
我需要在 IIS 中处理长时间运行的请求,处理请求本身非常轻量,但主要是由于 IO 需要花费大量时间。基本上我需要查询另一台服务器,该服务器有时会查询第三台服务器。所以我想同时处理尽可能多的请求。为此,我需要异步处理请求,我该如何正确处理?
使用 Socket 类,我可以轻松编写如下内容:
// ..listening code
// ..Accepting code
void CalledOnRecive(Request request)
{
//process the request a little
Context context = new Context()
context.Socket = request.Socket;
remoteServer.Begin_LongRunningDemonicMethod(request.someParameter, DoneCallBack, context);
}
void DoneCallBack( )
{
IAsyncresult result = remoteServer.Begin_CallSomeVeryLongRunningDemonicMethod( request.someParameter, DoneCallBack, context);
Socket socket = result.Context.Socket;
socket.Send(result.Result);
}
在上面的例子中,只要我调用“Begin...”方法就释放线程,并在另一个线程上发送响应,因此您可以轻松实现很高的并发性。 你如何在 IIS 内的 HTTP 处理程序中做同样的事情?
【问题讨论】:
标签: c# asp.net .net iis httphandler