Asynchronous handlers in asp.net

2,595 views
2,391 views

Published on

Here the speaker d

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,595
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
50
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Asynchronous handlers in asp.net

  1. 1. Asynchronous Handlers in ASP.NET KolkataGeeks
  2. 2. HTTP Handlers <ul><li>An ASP.NET HTTP handler is a process, which runs in response to a request made to an ASP.NET web application. </li></ul>KolkataGeeks Handler Description .aspx Default handler for all ASP.NET Web Pages .asmx Default handler for all Web Service Pages .ashx Default handler for all Web Handlers, that have no UI, instead have @WebHandler directive
  3. 3. Hierarchy IHttpHandler interface void ProcessRequest(HttpContext ctx); bool IsReusable {get;} IHttpAsyncHandler : IHttpHandler IAsyncResult BeginProcessRequest(HttpContext ctx, AsyncCallback cb, object obj); void EndProcessRequest(IAsyncResult ar); Implemented By Synchronous Handler Implemented By Asynchronous Handler KolkataGeeks
  4. 4. Synchronous Handler <ul><li>A synchronous handler returns only after complete processing of the HTTP request, for which it is called. </li></ul>KolkataGeeks
  5. 5. Synchronous Handler CLIENT THREAD POOL R1 T1 REQUEST QUEUE ERROR 503 KolkataGeeks
  6. 6. KolkataGeeks
  7. 7. KolkataGeeks
  8. 8. KolkataGeeks
  9. 9. Registering Http Handler in Web.Config file KolkataGeeks
  10. 10. KolkataGeeks
  11. 11. Asynchronous Handlers <ul><li>Asynchronous programming helps in better usage of resources. </li></ul><ul><li>In ASP.Net when a request is made, a thread is created and allocated to the handler file. the thread will be idle when the file will undergo i/o processing. </li></ul><ul><li>So to properly use the thread's idle time , we can release the thread back to thread pool after passing the execution to handler file. </li></ul><ul><li>When the I/O operation is complete, the framework reassigns a thread to the request and the handler can render the output to the browser. </li></ul>KolkataGeeks
  12. 12. Asynchronous Handler CLIENT BEGIN THREAD POOL END I/O PROCESS Thread 1 Thread 2 Thread 1 Released KolkataGeeks
  13. 13. IAsyncResult <ul><li>An asynchronous HTTP Handler uses an IAsyncResult object to notify when the operation has been completed. </li></ul><ul><li>Once the I/O or DB operation is completed, thread is reassigned, ASP.NET will continue the execution of the handler. </li></ul>KolkataGeeks
  14. 14. IsReusable Property <ul><li>If the handler returns static content, it is safe to be reusable. But if the handler returns dynamic content, to make it thread safe, IsReusable property should be set as false. </li></ul><ul><li>In such case, context switching may occur, which may cause the handler to give wrong output. </li></ul>KolkataGeeks
  15. 15. <ul><li>The verb=”*” attribute, we instruct the handler to process a request that uses any verb(for eg. POST,HEAD,GET, and so on.) </li></ul><ul><li>In the path=“*.sync” attribute, we instruct the handler to process any incoming requests for files with the .sync extension. </li></ul><ul><li>Type=“handler class name” </li></ul>KolkataGeeks
  16. 16. HTTPContext <ul><li>Encapsulates all HTTP-specific information about an individual HTTP request. </li></ul>KolkataGeeks
  17. 17. KolkataGeeks
  18. 18. KolkataGeeks
  19. 19. KolkataGeeks
  20. 20. Register Http Handler in Web.Config File KolkataGeeks
  21. 21. KolkataGeeks
  22. 22. If registration of Handler is not done in Web.Config File KolkataGeeks
  23. 23. Now Handler is registered for *.jpg in Web.Config File KolkataGeeks
  24. 24. KolkataGeeks

×