How do I use IHTTPAsyncHandler?

Imagine I have code to read from the beginning to the end of a file, for example:

while(sw.readline != null)
{

}

      

I want this to be completely asynchronous. When you exit IHTTPAsyncHandler, where will this code go and where would the code get the content of each line?

+1


source to share


1 answer


I recently added some asynchronous processes to my ASP.NET pages to allow some long running processes while the user was waiting for results. I found the IHTTPAsyncHandler to be pretty inadequate. All it does is let you spin a new thread while the page starts processing. You should still create your own thread and create an AsyncRequestResult.

Instead, I ended up using the normal stream in my code instead, much more concise:



using System;
using System.Web;
using System.Threading;

namespace Temp {
    public partial class thread : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {
            Thread thread = new Thread(new ThreadStart(myAsyncProcess));
            thread.Start();
        }

        private void myAsyncProcess() {
            // Long running process
        }
    }
}

      

-2


source







All Articles