AsyncModule.cs 933 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Web;
  3. namespace TestMonoWeb
  4. {
  5. /// <summary>
  6. /// Summary description for AsyncModule.
  7. /// </summary>
  8. public class AsyncModule : IHttpModule
  9. {
  10. HttpApplication _app;
  11. public void Init(HttpApplication app) {
  12. app.AddOnPreRequestHandlerExecuteAsync(
  13. new BeginEventHandler(this.BeginPreHandlerExecute),
  14. new EndEventHandler(this.EndPreHandlerExecute));
  15. _app = app;
  16. }
  17. IAsyncResult BeginPreHandlerExecute(Object source, EventArgs e, AsyncCallback cb, Object extraData) {
  18. ((HttpApplication) source).Context.Response.Write("AsyncModule.BeginPreHandlerExecute()<br>\n");
  19. AsynchOperation asynch = new AsynchOperation(cb, _app.Context, extraData);
  20. asynch.StartAsyncWork();
  21. return asynch;
  22. }
  23. void EndPreHandlerExecute(IAsyncResult ar) {
  24. ((AsynchOperation) ar).Context.Response.Write("AsyncModule.EndPreHandlerExecute()<br>\n");
  25. }
  26. public void Dispose() {
  27. }
  28. }
  29. }