Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:22:58+00:00 2026-06-05T13:22:58+00:00

I saw this aricle which describes implementing the IHttpAsyncHandler . Looking at this part:

  • 0

I saw this aricle which describes implementing the IHttpAsyncHandler.

Looking at this part:

public class MyAsyncHandler : IHttpAsyncHandler
{
    /// 
    /// The queue holds a list of asynchronous results
    /// with information about registered sessions
    /// 
    public static List<myasyncresult> Queue;


    static MyAsyncHandler()
    {
        // Initialize the queue
        Queue = new List<myasyncresult>();
    }



    public IAsyncResult BeginProcessRequest(HttpContext context, 
                        AsyncCallback cb, object extraData)
    {
        // Fetch the session id from the request
        var sessionId   = context.Request["sessionId"];

        // Check if the session is already registered
        if (Queue.Find(q => q.SessionId == sessionId) != null)
        {
            var index = Queue.IndexOf(Queue.Find(q => q.SessionId == sessionId));

            // The session has already been registered,
            // just refresh the HttpContext and the AsyncCallback
            Queue[index].Context  = context;
            Queue[index].Callback = cb;

            return Queue[index];
        }

        // Create a new AsyncResult that holds the information about the session
        var asyncResult = new MyAsyncResult(context, cb, sessionId);

        // This session has not been registered yet, add it to the queue
        Queue.Add(asyncResult);

        return asyncResult;
    }

    public void EndProcessRequest(IAsyncResult result)
    {
        var rslt  = (MyAsyncResult) result;

        // send the message to the recipient using
        // the recipients HttpContext.Response object
        rslt.Context.Response.Write(rslt.Message);

        // reset the message object
        rslt.Message = string.Empty;
    }


}

Where is the asynchronous part here? I dont see any BeginXXX method here.

Also I checked with Thread.CurrentThread.IsThreadPoolThread at the first line of BeginProcessRequest and it showed me TRUE.

So where is the asynchronous part here in this example?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:22:59+00:00Added an answer on June 5, 2026 at 1:22 pm

    When this handler receives a request, it will call BeginProcessRequest.
    It does not block the calling thread.

    When processing is complete it will call EndProcessRequest.

    This will leave your asp.net worker process threads free to serve other requests while this is processing.
    When EndProcessRequest is called, you get to send the processed result back to the client.

    Here is a lot of explanation about how asp.net manages threads during an async request lifecycle.

    During the lifetime of an asynchronous page, the context starts with
    just one thread from the ASP.NET thread pool. After the asynchronous
    requests have started, the context doesn’t include any threads. As the
    asynchronous requests complete, the thread pool threads executing
    their completion routines enter the context. These may be the same
    threads that initiated the requests but more likely would be whatever
    threads happen to be free at the time the operations complete.

    If multiple operations complete at once for the same application,
    AspNetSynchronizationContext will ensure that they execute one at a
    time. They may execute on any thread, but that thread will have the
    identity and culture of the original page.

    Some reasoning on when to use async:

    Having an async handler is only useful if to process the request you
    have other async steps available (such as an off-box database call or
    a long hard drive read that you can call async as well.) To do this
    properly you would chain async methods (ie BeginProcessRequest would
    call FileStream.BeginRead with the same (or seperate) callback and
    handle accordingly.)
    Refer here:
    http://msdn.microsoft.com/en-us/library/system.web.ihttpasynchandler.aspx

    Take a look at this very detailed explaination on how to use asynchronous handlers

    To build a truly effective asynchronous handler, you must spawn an
    additional thread by hand in response to BeginProcessRequest. There
    are three important aspects to building a successful asynchronous
    handler. First, construct a class that supports IAsyncResult to return
    from BeginProcessRequest. Then, spawn the thread to perform your
    request processing asynchronously. Finally, notify ASP.NET that you
    are finished processing the request and are ready to return the
    response.

    To summarize: if you are not creating a processing thread, or waiting for a long time, an async handler won’t do much good. When waiting, the request has no threads associated with it. This allows asp.net to scale well even with long waiting tasks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this in a part that never gets called in a coworker's code:
I saw this posting which explained how to get BC3 working as the diff
I saw an article detailing how to do this using attached behaviors which I
I'm looking at the Plugin Authoring article at http://docs.jquery.com/Plugins/Authoring and saw this example in
Hi I recently saw this article on how to store data into objects: $profile
I saw this question and some similar and I think it's not duplicate :
I saw this question on a forum: http://www.geeksforgeeks.org/archives/19042 Given an undirected graph and a
I saw this piece of code in jQuery's source. I am a novice in
I saw this beautiful script to add thousands separator to js numbers: function thousandSeparator(n,
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.