7

When a new async thread has been spawned using this signature, will the ASP.NET session object be available to the this new thread?

IAsyncResult asyncCall = f.BeginInvoke(null, f);
1

1 Answer 1

5

I don't know about which session object you are talking about but if you talk about the ASP.NET Session it might not be available. Also it is bad practice to access the ASP.NET Session from background threads. I would recommend you passing an object containing all the necessary information to this background tread instead of having it pull stuff from a session => makes it less reusable.

Normally if the caller of this thread waits for it to complete the session should be available all along but honestly it's bad design and I would simply avoid it.

6
  • Yes, it is the ASP.NET session object I'm talking about. And it is because ASP.NET session object is not thread-safe? Feb 23, 2011 at 20:41
  • 2
    And I would think that even if it's available when the thread starts, it could be disposed at any time, although if the caller is going to wait for the asynchronous task to complete before exiting, the session should remain through the task. Feb 23, 2011 at 20:42
  • @Jim, good point, I've updated my answer to include this information. Feb 23, 2011 at 20:44
  • @Darin So what is the best way to share objects between the background thread and the page? I'm facing the same issue. stackoverflow.com/questions/6152644/…
    – NLV
    May 27, 2011 at 13:55
  • @NLV, you could pass all the necessary information when starting the thread. As far as the thread passing information to the page is concerned, well, you will have to define what you mean by page as while the background thread executes the page that started this thread might be long gone. May 27, 2011 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.