AK_*_*AK_ 6 .net c# asp.net iis httphandler
我需要在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);
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,一旦我调用"Begin ..."方法就释放线程,并且响应在另一个线程上发送,因此您可以轻松实现非常高的并发性.你如何在IIS内的HTTP处理程序中做同样的事情?