Thursday, March 22, 2012

WorkItem class

Hi.

I have came across the WorkItem class under the System.Web.Utils (I didnt find any meaninfull documentation), I have used it to create an asynchronious mechanism for our web application.

There are somethigs that bother me:
1. When posting a new action, the action cannot throw an exception - If it does than the working process is crashed - WHY?
2. Why cany I find any documentation on it.
3. The delegate that is called doesnt have access to the httpcontext.Current - How can I use the context from with in the new function, Also is it safe to reference the context from an asynch function?

Thanks

WorkItem is a pretty raw class - I'm suprised it's marked as public. I'd use ThreadPool.QueueUserWorkItem instead - the result will be the same.
The HttpContext is tied to a specific thread. You won't get access to the context unless you pass it along to the worker thread, which can be a dangerous thing to do. If the original request thread finishes processing the request and then you access the context from a worker thread - the results can be unpredictable.
I think you'll want to look at Async Pages in ASP.NET 2.0 instead. I have some information about them here:
AsyncPages In ASP.NET 2.0
Tracing Threads InAsyncPages
Hi, Thanks for the reply.
I would like to implement a page that will register the async operation and than return back to the client showing him a wait image.
Using a call back I want to check if the async operation has completed.
Can it be done using this async method?
Thanks
No, but google will show you some different ways to achieve this:http://www.google.com/search?hl=en&lr=&c2coff=1&biw=871&q=asp.net+progress+bar

0 comments:

Post a Comment