G
Guest
Hi,
I need to write asynchronous HTTPModule which will sometimes execute long
job. I've written it using AddOnBeginRequestAsync but it still executes
synchronously - I am checking performance counters but after running X
requests which executes this "asynchronous" module all other requests go to
application queue - so it executes synchronously.
Code is based on the following article
http://msdn.microsoft.com/msdnmag/issues/07/03/WickedCode/#S3
This is my sample code
public class RequestDelayModule : BaseHTTPModule {
protected override void Init() {
base.Init();
this.Application.AddOnBeginRequestAsync(new
BeginEventHandler(BeginRequest_AsyncBegin), new
EndEventHandler(BeginRequest_AsyncEnd));
return;
}
delegate void ABR(HttpContext Context);
IAsyncResult BeginRequest_AsyncBegin(object sender, EventArgs e,
AsyncCallback cb, object state) {
return new ABR(Application_BeginRequest).BeginInvoke(null, cb,
this.Context);
}
void BeginRequest_AsyncEnd(IAsyncResult ar) {
return;
}
void Application_BeginRequest(HttpContext Context) {
Thread.Sleep(5 * 60 * 1000);
}
}
What's wrong on this code that AddOnBeginRequestAsync uses threads from same
thread pool as is used for serving other ASP.NET requests ?
All suggestions how to write HTTPModule asynchronously are welcome .
Many thanks.
I need to write asynchronous HTTPModule which will sometimes execute long
job. I've written it using AddOnBeginRequestAsync but it still executes
synchronously - I am checking performance counters but after running X
requests which executes this "asynchronous" module all other requests go to
application queue - so it executes synchronously.
Code is based on the following article
http://msdn.microsoft.com/msdnmag/issues/07/03/WickedCode/#S3
This is my sample code
public class RequestDelayModule : BaseHTTPModule {
protected override void Init() {
base.Init();
this.Application.AddOnBeginRequestAsync(new
BeginEventHandler(BeginRequest_AsyncBegin), new
EndEventHandler(BeginRequest_AsyncEnd));
return;
}
delegate void ABR(HttpContext Context);
IAsyncResult BeginRequest_AsyncBegin(object sender, EventArgs e,
AsyncCallback cb, object state) {
return new ABR(Application_BeginRequest).BeginInvoke(null, cb,
this.Context);
}
void BeginRequest_AsyncEnd(IAsyncResult ar) {
return;
}
void Application_BeginRequest(HttpContext Context) {
Thread.Sleep(5 * 60 * 1000);
}
}
What's wrong on this code that AddOnBeginRequestAsync uses threads from same
thread pool as is used for serving other ASP.NET requests ?
All suggestions how to write HTTPModule asynchronously are welcome .
Many thanks.