Forum Moderators: open
Here's the crack...I have a method. From this method I want to call another method asynchronously, which grabs something from a database, then sticks it in the cache, while the original method just returns so the user can keep on using the page.
I'm sure this is a very simple and common task...but I can't for the life of me get the second async method to put anything in the cache. I've tried even putting an arbitrary value in the Session when the callback of the async method is called...and while it seems to go into the session ok, when I inspect the session from the main thread, the value just ain't there.
Now...this is bugging me. Unfortunately I don't really understand the inner workings of threads in asp.net, so I could be trying to accomplish something that's physically impossible, if so can someone please let me know I'm barking up the wrong tree!
If anyone's got any advice for me, it would be greatly appreciated!
Thanks in advance,
B
Been working on this the past couple of days and I've learnt a bit more (sadly I'm no closer to a solution though!)
I created a test program and it seems that if the code (all the async and callback stuff) is done in a page's code-behind, it works fine. Can put stuff into the cache, and it works.
The problem seems to be because the class from which I need to call these methods is actually in a custom, static class. In the rest of the class I have to access the cache by using System.web.httpcontext.current.cache, but when I do that in my async method or my callback (which run in a separate thread) it throws an exception (Object reference not set to an instance of an object).
Does this help matters at all? If someone could please explain to me what's happening, or how I can access the cache in the original thread, I would be very grateful!
Cheers,
B