Imagine I have some code to read from the start to end of a file like so:
while(sw.readline != null) {
}
I want this to be fully asynchronous. When deriving from IHTTPAsyncHandler, where would this code go and where would would the code to get the content of each line go? I'm a little confused of how to use this interface as I haven't seen a good example on the net.
Thanks
-
I recently added some asynchronous processes to my ASP.NET pages in order to allow some long-running processes to take place while the user waited for the results. I found the IHTTPAsyncHandler quite inadequate. All it does is allow you to spin off a new thread while the page begins processing. You still have to make your own thread and create a AsyncRequestResult.
Instead I ended up just using a normal thread in my codebehind instead, much more succinct:
Thread thread = new Thread(new ThreadStart(myAsyncProcess)); thread.Start(); ... private void myAsyncProcess() { // Long running process }Joe Philllips : Wouldn't you be clueless as to when that function was finished?DavGarcia : Yes, usually I'd use this to just call a long running process and forget about it. But if I needed to know when it was done, or if it even finished, the end of the process can update a status in a database. If the web page you are on needs to know when it is done, say a progress bar followed by a "Completed!" message, you can have myAsyncProcess update a Session object periodically along the way. Then use a client-side timer (ASP.NET AJAX Timer, for example) to call a function on the server to check the Session status.
0 comments:
Post a Comment